15
15
16
16
class StandardCompiler implements CompilerInterface
17
17
{
18
- const BOOL_TRUE = '1 ' ;
19
- const BOOL_FALSE = '0 ' ;
18
+ private const BOOL_TRUE = '1 ' ;
19
+ private const BOOL_FALSE = '0 ' ;
20
20
21
- const LOGICAL_AND = '& ' ;
22
- const LOGICAL_OR = '| ' ;
21
+ private const LOGICAL_AND = '& ' ;
22
+ private const LOGICAL_OR = '| ' ;
23
23
24
- const OPENING_PARENTHESIS = '( ' ;
25
- const CLOSING_PARENTHESIS = ') ' ;
24
+ private const OPENING_PARENTHESIS = '( ' ;
25
+ private const CLOSING_PARENTHESIS = ') ' ;
26
26
27
- /** @var string */
28
- private $ output = '' ;
29
- /** @var int */
30
- private $ openParenthesis = 0 ;
31
- /** @var int */
32
- private $ closedParenthesis = 0 ;
27
+ private string $ output = '' ;
28
+ private int $ openParenthesis = 0 ;
29
+ private int $ closedParenthesis = 0 ;
33
30
34
31
public function getCompiledRule (): string
35
32
{
@@ -48,6 +45,7 @@ private function openParenthesis(): void
48
45
$ this ->output .= self ::OPENING_PARENTHESIS ;
49
46
}
50
47
48
+ /** @throws ParserException */
51
49
private function closeParenthesis (): void
52
50
{
53
51
if ($ this ->openParenthesis < 1 ) {
@@ -58,6 +56,7 @@ private function closeParenthesis(): void
58
56
$ this ->output .= self ::CLOSING_PARENTHESIS ;
59
57
}
60
58
59
+ /** @throws ParserException */
61
60
public function addParentheses (BaseToken $ token ): void
62
61
{
63
62
if ($ token instanceof TokenOpeningParenthesis) {
@@ -70,6 +69,7 @@ public function addParentheses(BaseToken $token): void
70
69
}
71
70
}
72
71
72
+ /** @throws ParserException */
73
73
public function addLogical (BaseToken $ token ): void
74
74
{
75
75
$ lastChar = $ this ->getLastChar ();
@@ -85,6 +85,7 @@ public function addLogical(BaseToken $token): void
85
85
}
86
86
}
87
87
88
+ /** @throws MissingOperatorException */
88
89
public function addBoolean (bool $ bool ): void
89
90
{
90
91
$ lastChar = $ this ->getLastChar ();
@@ -105,26 +106,24 @@ private function isIncompleteCondition(): bool
105
106
{
106
107
$ lastChar = $ this ->getLastChar ();
107
108
108
- return (
109
+ return
109
110
$ lastChar === self ::LOGICAL_AND ||
110
- $ lastChar === self ::LOGICAL_OR
111
- );
111
+ $ lastChar === self ::LOGICAL_OR ;
112
112
}
113
113
114
114
private function expectOpeningParenthesis (): bool
115
115
{
116
116
$ lastChar = $ this ->getLastChar ();
117
117
118
- return (
118
+ return
119
119
$ lastChar === '' ||
120
120
$ lastChar === self ::LOGICAL_AND ||
121
121
$ lastChar === self ::LOGICAL_OR ||
122
- $ lastChar === self ::OPENING_PARENTHESIS
123
- );
122
+ $ lastChar === self ::OPENING_PARENTHESIS ;
124
123
}
125
124
126
125
private function getLastChar (): string
127
126
{
128
- return substr ($ this ->output , -1 );
127
+ return substr ($ this ->output , offset: -1 );
129
128
}
130
129
}
0 commit comments