Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.12% |
16 / 17 |
|
90.00% |
9 / 10 |
CRAP | |
0.00% |
0 / 1 |
| KeywordNodeVisitor | |
94.12% |
16 / 17 |
|
90.00% |
9 / 10 |
14.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| visitWordsQueryNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitPhraseQueryNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitPhrasePrefixNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitFuzzyNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitPrefixNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitWildcardNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitEmptyQueryNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| visitKeywordFeatureNode | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| filterKeyword | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
4.07 | |||
| doVisitKeyword | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Parser\AST\Visitor; |
| 4 | |
| 5 | use CirrusSearch\Parser\AST\EmptyQueryNode; |
| 6 | use CirrusSearch\Parser\AST\FuzzyNode; |
| 7 | use CirrusSearch\Parser\AST\KeywordFeatureNode; |
| 8 | use CirrusSearch\Parser\AST\PhrasePrefixNode; |
| 9 | use CirrusSearch\Parser\AST\PhraseQueryNode; |
| 10 | use CirrusSearch\Parser\AST\PrefixNode; |
| 11 | use CirrusSearch\Parser\AST\WildcardNode; |
| 12 | use CirrusSearch\Parser\AST\WordsQueryNode; |
| 13 | |
| 14 | /** |
| 15 | * Simple KeywordFeatureNode visitor |
| 16 | */ |
| 17 | abstract class KeywordNodeVisitor extends LeafVisitor { |
| 18 | |
| 19 | /** |
| 20 | * @var string[] class names to accept (empty to accept all) |
| 21 | */ |
| 22 | private $keywordClasses; |
| 23 | |
| 24 | /** |
| 25 | * @param array $excludeOccurs list of boolean accurence type to ignore |
| 26 | * @param array $keywordClasses list of KeywordFeature classes to accept (empty to accept them all) |
| 27 | */ |
| 28 | public function __construct( array $excludeOccurs = [], array $keywordClasses = [] ) { |
| 29 | parent::__construct( $excludeOccurs ); |
| 30 | $this->keywordClasses = $keywordClasses; |
| 31 | } |
| 32 | |
| 33 | final public function visitWordsQueryNode( WordsQueryNode $node ) { |
| 34 | } |
| 35 | |
| 36 | final public function visitPhraseQueryNode( PhraseQueryNode $node ) { |
| 37 | } |
| 38 | |
| 39 | final public function visitPhrasePrefixNode( PhrasePrefixNode $node ) { |
| 40 | } |
| 41 | |
| 42 | final public function visitFuzzyNode( FuzzyNode $node ) { |
| 43 | } |
| 44 | |
| 45 | final public function visitPrefixNode( PrefixNode $node ) { |
| 46 | } |
| 47 | |
| 48 | final public function visitWildcardNode( WildcardNode $node ) { |
| 49 | } |
| 50 | |
| 51 | final public function visitEmptyQueryNode( EmptyQueryNode $node ) { |
| 52 | } |
| 53 | |
| 54 | final public function visitKeywordFeatureNode( KeywordFeatureNode $node ) { |
| 55 | if ( $this->filterKeyword( $node ) ) { |
| 56 | $this->doVisitKeyword( $node ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param KeywordFeatureNode $node |
| 62 | * @return bool |
| 63 | */ |
| 64 | private function filterKeyword( KeywordFeatureNode $node ) { |
| 65 | if ( $this->keywordClasses === [] ) { |
| 66 | return true; |
| 67 | } |
| 68 | foreach ( $this->keywordClasses as $class ) { |
| 69 | if ( $node->getKeyword() instanceof $class ) { |
| 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @param KeywordFeatureNode $node |
| 78 | * @return void |
| 79 | */ |
| 80 | abstract public function doVisitKeyword( KeywordFeatureNode $node ); |
| 81 | } |