Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
66.67% |
4 / 6 |
CRAP | |
61.54% |
8 / 13 |
NegatedNode | |
0.00% |
0 / 1 |
|
66.67% |
4 / 6 |
11.64 | |
61.54% |
8 / 13 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
toArray | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
getChild | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
validNegationType | |
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
|||
getNegationType | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
accept | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
<?php | |
namespace CirrusSearch\Parser\AST; | |
use CirrusSearch\Parser\AST\Visitor\Visitor; | |
use Wikimedia\Assert\Assert; | |
/** | |
* Negated node | |
* NOTE: may not appear in any resulting query AST, | |
* NegatedNode are always removed and attached to a BooleanClause | |
* as MUST_NOT. | |
*/ | |
class NegatedNode extends ParsedNode { | |
/** | |
* @var ParsedNode | |
*/ | |
private $child; | |
/** | |
* @var string type of negation used | |
*/ | |
private $negationType; | |
/** | |
* @param int $startOffset | |
* @param int $endOffset | |
* @param ParsedNode $child | |
* @param string $negationType | |
*/ | |
public function __construct( $startOffset, $endOffset, ParsedNode $child, $negationType ) { | |
Assert::parameter( self::validNegationType( $negationType ), 'negationType', 'Invalid negation type provided' ); | |
parent::__construct( $startOffset, $endOffset ); | |
$this->child = $child; | |
$this->negationType = $negationType; | |
} | |
/** | |
* @return array | |
*/ | |
public function toArray() { | |
return [ 'not' => array_merge( parent::baseParams(), [ | |
'negation_type' => $this->negationType, | |
'child' => $this->child->toArray(), | |
] ) ]; | |
} | |
/** | |
* @return ParsedNode | |
*/ | |
public function getChild() { | |
return $this->child; | |
} | |
/** | |
* Check whether this negation type is valid | |
* @param string $negationType | |
* @return bool | |
*/ | |
public static function validNegationType( $negationType ) { | |
return $negationType === '!' || $negationType === '-' || $negationType === 'NOT'; | |
} | |
/** | |
* @return string type of negation used (NOT, ! or -) | |
*/ | |
public function getNegationType() { | |
return $this->negationType; | |
} | |
/** | |
* @param Visitor $visitor | |
*/ | |
public function accept( Visitor $visitor ) { | |
$visitor->visitNegatedNode( $this ); | |
} | |
} |