1717 */
1818class TextParser
1919{
20- private $ tokens = [];
21- private $ text = '' ;
22- private $ symbol = null ;
23- private $ value = null ;
24- private $ done = true ;
25- private $ options = [];
20+ /**
21+ * @var array<string, string>
22+ */
23+ private array $ tokens = [];
24+
25+ private string $ text = '' ;
26+
27+ private ?string $ symbol = null ;
28+
29+ /**
30+ * @var array<string>|null
31+ */
32+ private ?array $ value = null ;
33+
34+ private bool $ done = true ;
35+
36+ /**
37+ * @var array<string, mixed>
38+ */
39+ private array $ options = [];
2640
2741 public function __construct ()
2842 {
@@ -33,9 +47,9 @@ public function __construct()
3347 * Parse natural language text into Rule options array
3448 *
3549 * @param string $text Natural language text describing recurrence
36- * @return array Options array suitable for Rule constructor
50+ * @return array<string, mixed>|null Options array suitable for Rule constructor
3751 */
38- public function parseText ($ text )
52+ public function parseText (string $ text ): ? array
3953 {
4054 $ this ->options = [];
4155 $ this ->text = strtolower (trim ($ text ));
@@ -55,7 +69,7 @@ public function parseText($text)
5569 }
5670 }
5771
58- private function initializeTokens ()
72+ private function initializeTokens (): void
5973 {
6074 $ this ->tokens = [
6175 'SKIP ' => '/^[ \r\n\t]+|^\.$/i ' ,
@@ -101,7 +115,7 @@ private function initializeTokens()
101115 ];
102116 }
103117
104- private function nextSymbol ()
118+ private function nextSymbol (): bool
105119 {
106120 $ this ->symbol = null ;
107121 $ this ->value = null ;
@@ -143,7 +157,11 @@ private function nextSymbol()
143157 return true ;
144158 }
145159
146- private function accept ($ name )
160+ /**
161+ * @param string $name
162+ * @return array<string>|false
163+ */
164+ private function accept (string $ name ): array |false
147165 {
148166 if ($ this ->symbol === $ name ) {
149167 $ value = $ this ->value ;
@@ -153,25 +171,32 @@ private function accept($name)
153171 return false ;
154172 }
155173
156- private function expect ($ name )
174+ /**
175+ * @param string $name
176+ * @return bool
177+ */
178+ private function expect (string $ name ): bool
157179 {
158180 if ($ this ->accept ($ name )) {
159181 return true ;
160182 }
161183 throw new InvalidArgument ("Expected $ name but found " . $ this ->symbol );
162184 }
163185
164- private function acceptNumber ()
186+ /**
187+ * @return array<string>|false
188+ */
189+ private function acceptNumber (): array |false
165190 {
166191 return $ this ->accept ('number ' );
167192 }
168193
169- private function isDone ()
194+ private function isDone (): bool
170195 {
171196 return $ this ->done && $ this ->symbol === null ;
172197 }
173198
174- private function parseStatement ()
199+ private function parseStatement (): void
175200 {
176201 // every [n]
177202 $ this ->expect ('every ' );
0 commit comments