Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
BooleanClause | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
9.03 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
getNode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateOccur | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
getOccur | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isExplicit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
accept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNegatedNode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Parser\AST; |
4 | |
5 | use CirrusSearch\Parser\AST\Visitor\Visitable; |
6 | use CirrusSearch\Parser\AST\Visitor\Visitor; |
7 | use Wikimedia\Assert\Assert; |
8 | |
9 | /** |
10 | * A boolean clause |
11 | */ |
12 | class BooleanClause implements Visitable { |
13 | public const MUST = 'MUST'; |
14 | public const SHOULD = 'SHOULD'; |
15 | public const MUST_NOT = 'MUST_NOT'; |
16 | |
17 | /** |
18 | * @var ParsedNode |
19 | */ |
20 | private $node; |
21 | |
22 | /** |
23 | * Specifies how this clause is to occur in matching documents |
24 | * @var string |
25 | */ |
26 | private $occur; |
27 | |
28 | /** |
29 | * @var bool true if the node is explicitly connected |
30 | */ |
31 | private $explicit; |
32 | |
33 | private ?NegatedNode $negatedNode; |
34 | |
35 | /** |
36 | * @param ParsedNode $node |
37 | * @param string $occur Specifies how this clause is to occur in matching documents. |
38 | * @param bool $explicit whether or not this node is explicitly connected |
39 | * @param NegatedNode|null $negatedNode when in a MUST_NOT, remember how this clause was negated |
40 | * acceptable values are BooleanClause::MUST, BooleanClause::MUST_NOT and BooleanClause::SHOULD |
41 | */ |
42 | public function __construct( ParsedNode $node, $occur, $explicit, ?NegatedNode $negatedNode = null ) { |
43 | $this->node = $node; |
44 | $this->occur = $occur; |
45 | self::validateOccur( $occur ); |
46 | Assert::parameter( ( $occur === self::MUST_NOT ) === ( $negatedNode !== null ), '$negatedNode', |
47 | 'A NegatedNode must be provided only if occur is MUST_NOT' ); |
48 | $this->explicit = $explicit; |
49 | $this->negatedNode = $negatedNode; |
50 | } |
51 | |
52 | /** |
53 | * @return ParsedNode |
54 | */ |
55 | public function getNode() { |
56 | return $this->node; |
57 | } |
58 | |
59 | /** |
60 | * Check if $occur is valid |
61 | * @param string $occur |
62 | */ |
63 | public static function validateOccur( $occur ) { |
64 | Assert::parameter( $occur === self::MUST || $occur === self::SHOULD || $occur === self::MUST_NOT, |
65 | '$occur', 'must be either: MUST, SHOULD or MUST_NOT' ); |
66 | } |
67 | |
68 | /** |
69 | * Specifies how this clause is to occur in matching documents |
70 | * @return string |
71 | */ |
72 | public function getOccur() { |
73 | return $this->occur; |
74 | } |
75 | |
76 | /** |
77 | * @return bool |
78 | */ |
79 | public function isExplicit() { |
80 | return $this->explicit; |
81 | } |
82 | |
83 | /** |
84 | * @param Visitor $visitor |
85 | */ |
86 | public function accept( Visitor $visitor ) { |
87 | $visitor->visitBooleanClause( $this ); |
88 | } |
89 | |
90 | /** |
91 | * |
92 | * @return NegatedNode|null |
93 | */ |
94 | public function getNegatedNode(): ?NegatedNode { |
95 | return $this->negatedNode; |
96 | } |
97 | } |