Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
30 / 33
70.00% covered (warning)
70.00%
7 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
KeywordFeatureNode
90.91% covered (success)
90.91%
30 / 33
70.00% covered (warning)
70.00%
7 / 10
10.08
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 getKeyword
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getKey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQuotedValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDelimiter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSuffix
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getParsedValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
 accept
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace CirrusSearch\Parser\AST;
4
5use CirrusSearch\Parser\AST\Visitor\Visitor;
6use CirrusSearch\Query\KeywordFeature;
7
8/**
9 * Represents a keyword in the query
10 */
11class KeywordFeatureNode extends ParsedNode {
12
13    /**
14     * @var KeywordFeature
15     */
16    private $keyword;
17
18    /**
19     * @var string
20     */
21    private $key;
22
23    /**
24     * @var string
25     */
26    private $value;
27
28    /**
29     * @var string
30     */
31    private $quotedValue;
32
33    /**
34     * @var string
35     */
36    private $delimiter;
37
38    /**
39     * @var string
40     */
41    private $suffix;
42
43    /**
44     * Parsed value
45     * @see KeywordFeature::parseValue()
46     * @var array|null
47     */
48    private $parsedValue;
49
50    /**
51     * @param int $startOffset
52     * @param int $endOffset
53     * @param KeywordFeature $keyword
54     * @param string $key
55     * @param string $value
56     * @param string $quotedValue
57     * @param string $delimiter
58     * @param string $suffix
59     * @param array|null $parsedValue value as parsed by KeywordFeature::parseValue()
60     * @see KeywordFeature::parseValue()
61     */
62    public function __construct(
63        $startOffset,
64        $endOffset,
65        KeywordFeature $keyword,
66        $key,
67        $value,
68        $quotedValue,
69        $delimiter,
70        $suffix,
71        array $parsedValue = null
72    ) {
73        parent::__construct( $startOffset, $endOffset );
74        $this->keyword = $keyword;
75        $this->key = $key;
76        $this->value = $value;
77        $this->quotedValue = $quotedValue;
78        $this->delimiter = $delimiter;
79        $this->suffix = $suffix;
80        $this->parsedValue = $parsedValue;
81    }
82
83    /**
84     * The feature
85     * @return KeywordFeature
86     */
87    public function getKeyword() {
88        return $this->keyword;
89    }
90
91    /**
92     * The keyword prefix used
93     * @return string
94     */
95    public function getKey() {
96        return $this->key;
97    }
98
99    /**
100     * The value (unescaped)
101     * @return string
102     */
103    public function getValue() {
104        return $this->value;
105    }
106
107    /**
108     * The quoted as-is
109     * @return string
110     */
111    public function getQuotedValue() {
112        return $this->quotedValue;
113    }
114
115    /**
116     * The delimiter used to wrap the value
117     * @return string
118     */
119    public function getDelimiter() {
120        return $this->delimiter;
121    }
122
123    /**
124     * The optional value suffix used in the query
125     * @return string
126     */
127    public function getSuffix() {
128        return $this->suffix;
129    }
130
131    /**
132     * Return the value parsed by the KeywordFeature implementation
133     *
134     * NOTE: Only the keyword implementation knows what to do with this data
135     * @return array|null
136     * @see KeywordFeature::parseValue()
137     */
138    public function getParsedValue() {
139        return $this->parsedValue;
140    }
141
142    /**
143     * @return array
144     */
145    public function toArray() {
146        return [
147            "keyword" => array_merge(
148                $this->baseParams(),
149                array_filter( [
150                        "keyword" => get_class( $this->keyword ),
151                        "key" => $this->key,
152                        "value" => $this->value,
153                        "quotedValue" => $this->quotedValue,
154                        "delimiter" => $this->delimiter,
155                        "suffix" => $this->suffix,
156                        "parsedValue" => $this->parsedValue,
157                    ], static function ( $x ) {
158                        return $x !== null;
159                    }
160                )
161            )
162        ];
163    }
164
165    /**
166     * @param Visitor $visitor
167     */
168    public function accept( Visitor $visitor ) {
169        $visitor->visitKeywordFeatureNode( $this );
170    }
171}