Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
80.95% |
17 / 21 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
ParseWarning | |
80.95% |
17 / 21 |
|
42.86% |
3 / 7 |
10.69 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getExpectedTokens | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getActualToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStart | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMessageParams | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toArray | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Parser\AST; |
4 | |
5 | /** |
6 | * A warning that occurred during the parse process. |
7 | */ |
8 | class ParseWarning { |
9 | /** |
10 | * @var string |
11 | */ |
12 | private $message; |
13 | |
14 | /** |
15 | * @var string[] |
16 | */ |
17 | private $expectedTokens; |
18 | |
19 | /** |
20 | * @var string |
21 | */ |
22 | private $actualToken; |
23 | /** |
24 | * @var int |
25 | */ |
26 | private $start; |
27 | |
28 | /** |
29 | * @var string[] |
30 | */ |
31 | private $messageParams; |
32 | |
33 | /** |
34 | * @param string $message |
35 | * @param int $start |
36 | * @param string[] $expectedTokens |
37 | * @param string|null $actualToken |
38 | * @param mixed[] $messageParams |
39 | */ |
40 | public function __construct( $message, $start, array $expectedTokens = [], $actualToken = null, array $messageParams = [] ) { |
41 | $this->message = $message; |
42 | $this->expectedTokens = $expectedTokens; |
43 | $this->actualToken = $actualToken; |
44 | $this->start = $start; |
45 | $this->messageParams = $messageParams; |
46 | } |
47 | |
48 | /** |
49 | * message code |
50 | * @return string |
51 | */ |
52 | public function getMessage() { |
53 | return $this->message; |
54 | } |
55 | |
56 | /** |
57 | * Token types that were expected |
58 | * The type names are parser dependent but should provide meaningful |
59 | * hints to the user |
60 | * @return string[] |
61 | */ |
62 | public function getExpectedTokens() { |
63 | return $this->expectedTokens; |
64 | } |
65 | |
66 | /** |
67 | * Token found |
68 | * @return string |
69 | */ |
70 | public function getActualToken() { |
71 | return $this->actualToken; |
72 | } |
73 | |
74 | /** |
75 | * Offset of the error. |
76 | * NOTE: Offset in byte (mb_strcut if you want to provide feedback and print the error in context) |
77 | * @return int |
78 | */ |
79 | public function getStart() { |
80 | return $this->start; |
81 | } |
82 | |
83 | /** |
84 | * @return mixed[] |
85 | */ |
86 | public function getMessageParams() { |
87 | return $this->messageParams; |
88 | } |
89 | |
90 | /** |
91 | * @return array |
92 | */ |
93 | public function toArray() { |
94 | $ar = [ |
95 | 'msg' => $this->message, |
96 | 'start' => $this->getStart(), |
97 | ]; |
98 | if ( $this->expectedTokens !== [] ) { |
99 | $ar['expected'] = $this->expectedTokens; |
100 | } |
101 | if ( $this->actualToken !== null ) { |
102 | $ar['actual'] = $this->actualToken; |
103 | } |
104 | if ( $this->messageParams !== [] ) { |
105 | $ar['message_params'] = $this->messageParams; |
106 | } |
107 | return $ar; |
108 | } |
109 | } |