3333 */
3434abstract class BaseTokenizer
3535{
36- /**
37- * @var string SQL code.
38- */
39- private string $ sql ;
40-
4136 /**
4237 * @var int SQL code string length.
4338 */
@@ -76,11 +71,14 @@ abstract class BaseTokenizer
7671 /**
7772 * @var SqlToken|null resulting token of a last {@see tokenize()} call.
7873 */
79- private ?SqlToken $ token = null ;
80-
81- public function __construct (string $ sql )
82- {
83- $ this ->sql = $ sql ;
74+ private SqlToken |null $ token = null ;
75+
76+ public function __construct (
77+ /**
78+ * @var string SQL code.
79+ */
80+ private string $ sql
81+ ) {
8482 }
8583
8684 /**
@@ -173,7 +171,7 @@ abstract protected function isComment(int &$length): bool;
173171 *
174172 * @return bool whether there's an operator at the current offset.
175173 */
176- abstract protected function isOperator (int &$ length , ? string &$ content ): bool ;
174+ abstract protected function isOperator (int &$ length , string | null &$ content ): bool ;
177175
178176 /**
179177 * Returns whether there's an identifier at the current offset.
@@ -186,7 +184,7 @@ abstract protected function isOperator(int &$length, ?string &$content): bool;
186184 *
187185 * @return bool whether there's an identifier at the current offset.
188186 */
189- abstract protected function isIdentifier (int &$ length , ? string &$ content ): bool ;
187+ abstract protected function isIdentifier (int &$ length , string | null &$ content ): bool ;
190188
191189 /**
192190 * Returns whether there's a string literal at the current offset.
@@ -199,7 +197,7 @@ abstract protected function isIdentifier(int &$length, ?string &$content): bool;
199197 *
200198 * @return bool whether there's a string literal at the current offset.
201199 */
202- abstract protected function isStringLiteral (int &$ length , ? string &$ content ): bool ;
200+ abstract protected function isStringLiteral (int &$ length , string | null &$ content ): bool ;
203201
204202 /**
205203 * Returns whether the given string is a keyword.
@@ -211,11 +209,8 @@ abstract protected function isStringLiteral(int &$length, ?string &$content): bo
211209 *
212210 * @return bool whether the given string is a keyword.
213211 */
214- abstract protected function isKeyword (string $ string , ? string &$ content ): bool ;
212+ abstract protected function isKeyword (string $ string , string | null &$ content ): bool ;
215213
216- /**
217- * @param string $sql
218- */
219214 public function setSql (string $ sql ): void
220215 {
221216 $ this ->sql = $ sql ;
@@ -237,16 +232,14 @@ protected function startsWithAnyLongest(
237232 array $ with ,
238233 bool $ caseSensitive ,
239234 int &$ length ,
240- ? string &$ content = null
235+ string &$ content = null
241236 ): bool {
242237 if (empty ($ with )) {
243238 return false ;
244239 }
245240
246241 if (!is_array (reset ($ with ))) {
247- usort ($ with , static function (string $ string1 , string $ string2 ) {
248- return mb_strlen ($ string2 , 'UTF-8 ' ) - mb_strlen ($ string1 , 'UTF-8 ' );
249- });
242+ usort ($ with , static fn (string $ string1 , string $ string2 ) => mb_strlen ($ string2 , 'UTF-8 ' ) - mb_strlen ($ string1 , 'UTF-8 ' ));
250243
251244 $ map = [];
252245
@@ -279,7 +272,7 @@ protected function startsWithAnyLongest(
279272 *
280273 * @return string result string, it may be empty if there's nothing to return.
281274 */
282- protected function substring (int $ length , bool $ caseSensitive = true , ? int $ offset = null ): string
275+ protected function substring (int $ length , bool $ caseSensitive = true , int $ offset = null ): string
283276 {
284277 if ($ offset === null ) {
285278 $ offset = $ this ->offset ;
@@ -310,7 +303,7 @@ protected function substring(int $length, bool $caseSensitive = true, ?int $offs
310303 *
311304 * @return int index after the given string or end of string index.
312305 */
313- protected function indexAfter (string $ string , ? int $ offset = null ): int
306+ protected function indexAfter (string $ string , int $ offset = null ): int
314307 {
315308 if ($ offset === null ) {
316309 $ offset = $ this ->offset ;
@@ -333,10 +326,6 @@ protected function indexAfter(string $string, ?int $offset = null): int
333326
334327 /**
335328 * Determines whether there is a delimited string at the current offset and adds it to the token children.
336- *
337- * @param int $length
338- *
339- * @return bool
340329 */
341330 private function tokenizeDelimitedString (int &$ length ): bool
342331 {
@@ -360,10 +349,6 @@ private function tokenizeDelimitedString(int &$length): bool
360349
361350 /**
362351 * Determines whether there is an operator at the current offset and adds it to the token children.
363- *
364- * @param int $length
365- *
366- * @return bool
367352 */
368353 private function tokenizeOperator (int &$ length ): bool
369354 {
@@ -457,8 +442,6 @@ private function addTokenFromBuffer(): void
457442 /**
458443 * Adds the specified length to the current offset.
459444 *
460- * @param int $length
461- *
462445 * @throws InvalidArgumentException
463446 */
464447 private function advance (int $ length ): void
@@ -473,8 +456,6 @@ private function advance(int $length): void
473456
474457 /**
475458 * Returns whether the SQL code is completely traversed.
476- *
477- * @return bool
478459 */
479460 private function isEof (): bool
480461 {
0 commit comments