diff --git a/src/Token/Token.php b/src/Token/Token.php index 8dbae315..1e7a1236 100644 --- a/src/Token/Token.php +++ b/src/Token/Token.php @@ -10,21 +10,21 @@ final class Token { // From Twig\Token - public const EOF_TYPE = -1; - public const TEXT_TYPE = 0; - public const BLOCK_START_TYPE = 1; - public const VAR_START_TYPE = 2; - public const BLOCK_END_TYPE = 3; - public const VAR_END_TYPE = 4; - public const NAME_TYPE = 5; - public const NUMBER_TYPE = 6; - public const STRING_TYPE = 7; - public const OPERATOR_TYPE = 8; - public const PUNCTUATION_TYPE = 9; - public const INTERPOLATION_START_TYPE = 10; - public const INTERPOLATION_END_TYPE = 11; - public const ARROW_TYPE = 12; - public const SPREAD_TYPE = 13; + public const EOF_TYPE = 'EOF_TYPE'; + public const TEXT_TYPE = 'TEXT_TYPE'; + public const BLOCK_START_TYPE = 'BLOCK_START_TYPE'; + public const VAR_START_TYPE = 'VAR_START_TYPE'; + public const BLOCK_END_TYPE = 'BLOCK_END_TYPE'; + public const VAR_END_TYPE = 'VAR_END_TYPE'; + public const NAME_TYPE = 'NAME_TYPE'; + public const NUMBER_TYPE = 'NUMBER_TYPE'; + public const STRING_TYPE = 'STRING_TYPE'; + public const OPERATOR_TYPE = 'OPERATOR_TYPE'; + public const PUNCTUATION_TYPE = 'PUNCTUATION_TYPE'; + public const INTERPOLATION_START_TYPE = 'INTERPOLATION_START_TYPE'; + public const INTERPOLATION_END_TYPE = 'INTERPOLATION_END_TYPE'; + public const ARROW_TYPE = 'ARROW_TYPE'; + public const SPREAD_TYPE = 'SPREAD_TYPE'; // New constants public const DQ_STRING_START_TYPE = 'DQ_STRING_START_TYPE'; public const DQ_STRING_END_TYPE = 'DQ_STRING_END_TYPE'; @@ -94,7 +94,7 @@ final class Token ]; public function __construct( - private int|string $type, + private string $type, private int $line, private int $linePosition, private string $filename, @@ -103,12 +103,12 @@ public function __construct( ) { } - public function getType(): int|string + public function getType(): string { return $this->type; } - public function setType(int|string $type): void + public function setType(string $type): void { $this->type = $type; } @@ -144,10 +144,10 @@ public function setRelatedToken(self $token): void } /** - * @param int|string|array $type - * @param string|string[] $value + * @param string|string[] $type + * @param string|string[] $value */ - public function isMatching(int|string|array $type, string|array $value = []): bool + public function isMatching(string|array $type, string|array $value = []): bool { if (!\is_array($type)) { $type = [$type]; diff --git a/src/Token/Tokenizer.php b/src/Token/Tokenizer.php index d950fbc0..cd058af1 100644 --- a/src/Token/Tokenizer.php +++ b/src/Token/Tokenizer.php @@ -285,7 +285,7 @@ private function moveCurrentExpressionStarter(): void ++$this->currentExpressionStarter; } - private function pushToken(int|string $type, string $value = '', ?Token $relatedToken = null): Token + private function pushToken(string $type, string $value = '', ?Token $relatedToken = null): Token { $token = new Token( $type, diff --git a/src/Token/Tokens.php b/src/Token/Tokens.php index 17ddfa5d..d3372d64 100644 --- a/src/Token/Tokens.php +++ b/src/Token/Tokens.php @@ -98,9 +98,9 @@ public function toArray(): array } /** - * @param int|string|array $type + * @param string|string[] $type */ - public function findNext(int|string|array $type, int $start, ?int $end = null, bool $exclude = false): int|false + public function findNext(string|array $type, int $start, ?int $end = null, bool $exclude = false): int|false { $end ??= $this->tokenCount; for ($i = $start; $i < $end; ++$i) { @@ -113,9 +113,9 @@ public function findNext(int|string|array $type, int $start, ?int $end = null, b } /** - * @param int|string|array $type + * @param string|string[] $type */ - public function findPrevious(int|string|array $type, int $start, int $end = 0, bool $exclude = false): int|false + public function findPrevious(string|array $type, int $start, int $end = 0, bool $exclude = false): int|false { for ($i = $start; $i >= $end; --$i) { if ($exclude !== $this->get($i)->isMatching($type)) { diff --git a/tests/Token/Tokenizer/TokenizerTest.php b/tests/Token/Tokenizer/TokenizerTest.php index 66cc5fb1..6cc5a936 100644 --- a/tests/Token/Tokenizer/TokenizerTest.php +++ b/tests/Token/Tokenizer/TokenizerTest.php @@ -128,7 +128,7 @@ public function testTokenizeIgnoredViolations(): void } /** - * @param array $expectedTokenTypes + * @param array $expectedTokenTypes * * @dataProvider tokenizeDataProvider */ @@ -151,13 +151,13 @@ public function testTokenizeTypes(string $filePath, array $expectedTokenTypes): static::fail($diff); } - $tokenTypes = array_map(static fn (Token $token): int|string => $token->getType(), $tokens->toArray()); + $tokenTypes = array_map(static fn (Token $token): string => $token->getType(), $tokens->toArray()); static::assertSame($expectedTokenTypes, $tokenTypes); static::assertTrue($tokens->isReadOnly()); } /** - * @return iterable}> + * @return iterable}> */ public static function tokenizeDataProvider(): iterable {