Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| NamespaceHeaderNode | |
90.91% |
10 / 11 |
|
75.00% |
3 / 4 |
5.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| toArray | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getNamespace | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| accept | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Parser\AST; |
| 4 | |
| 5 | use CirrusSearch\Parser\AST\Visitor\Visitor; |
| 6 | use Wikimedia\Assert\Assert; |
| 7 | |
| 8 | /** |
| 9 | * A "namespace header" in the query. |
| 10 | * Queries can be prefixed with a namespace header that allows to bypass |
| 11 | * namespaces selection made with API params or Special:Search UI. |
| 12 | * e.g.: |
| 13 | * - help:foobar |
| 14 | * |
| 15 | * will search foobar in NS_HELP no matter what is selected previously. |
| 16 | */ |
| 17 | class NamespaceHeaderNode extends ParsedNode { |
| 18 | /** |
| 19 | * @var string|int "all" or a int |
| 20 | */ |
| 21 | private $namespace; |
| 22 | |
| 23 | /** |
| 24 | * @param int $startOffset |
| 25 | * @param int $endOffset |
| 26 | * @param int|string $namespace "all" or a int. |
| 27 | */ |
| 28 | public function __construct( $startOffset, $endOffset, $namespace ) { |
| 29 | parent::__construct( $startOffset, $endOffset ); |
| 30 | Assert::parameter( is_int( $namespace ) || $namespace === 'all', |
| 31 | '$namespace', 'must be null, an integer or a string equals to "all"' ); |
| 32 | $this->namespace = $namespace; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @return array |
| 37 | */ |
| 38 | public function toArray() { |
| 39 | return [ |
| 40 | 'namespaceHeader' => array_merge( parent::baseParams(), [ |
| 41 | 'namespace' => $this->namespace |
| 42 | ] ) |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @return int|string |
| 48 | */ |
| 49 | public function getNamespace() { |
| 50 | return $this->namespace; |
| 51 | } |
| 52 | |
| 53 | public function accept( Visitor $visitor ) { |
| 54 | $visitor->visitNamespaceHeader( $this ); |
| 55 | } |
| 56 | } |