Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
10 / 12 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| FuzzyNode | |
83.33% |
10 / 12 |
|
60.00% |
3 / 5 |
7.23 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| toArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getWord | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFuzziness | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| accept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Parser\AST; |
| 4 | |
| 5 | use CirrusSearch\Parser\AST\Visitor\Visitor; |
| 6 | use Wikimedia\Assert\Assert; |
| 7 | |
| 8 | class FuzzyNode extends ParsedNode { |
| 9 | |
| 10 | /** |
| 11 | * @var string the word |
| 12 | */ |
| 13 | private $word; |
| 14 | |
| 15 | /** |
| 16 | * @var int 0, 1 or 2. -1 meaning that it was not provided by the user |
| 17 | */ |
| 18 | private $fuzziness; |
| 19 | |
| 20 | /** |
| 21 | * @param int $start |
| 22 | * @param int $end |
| 23 | * @param string $word |
| 24 | * @param int $fuzziness |
| 25 | */ |
| 26 | public function __construct( $start, $end, $word, $fuzziness ) { |
| 27 | parent::__construct( $start, $end ); |
| 28 | Assert::parameter( is_int( $fuzziness ) && $fuzziness >= -1 && $fuzziness < 3, |
| 29 | 'fuzziness', ' must be an integer in the [-1,2] range' ); |
| 30 | $this->word = $word; |
| 31 | $this->fuzziness = $fuzziness; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return array |
| 36 | */ |
| 37 | public function toArray() { |
| 38 | return [ 'fuzzy' => array_merge( parent::baseParams(), [ |
| 39 | 'word' => $this->word, |
| 40 | 'fuzziness' => $this->fuzziness, |
| 41 | ] ) ]; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return string the fuzzy word to search |
| 46 | */ |
| 47 | public function getWord() { |
| 48 | return $this->word; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return int |
| 53 | */ |
| 54 | public function getFuzziness() { |
| 55 | return $this->fuzziness; |
| 56 | } |
| 57 | |
| 58 | public function accept( Visitor $visitor ) { |
| 59 | $visitor->visitFuzzyNode( $this ); |
| 60 | } |
| 61 | } |