Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/Token/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -144,10 +144,10 @@ public function setRelatedToken(self $token): void
}

/**
* @param int|string|array<int|string> $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];
Expand Down
2 changes: 1 addition & 1 deletion src/Token/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/Token/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public function toArray(): array
}

/**
* @param int|string|array<int|string> $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) {
Expand All @@ -113,9 +113,9 @@ public function findNext(int|string|array $type, int $start, ?int $end = null, b
}

/**
* @param int|string|array<int|string> $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)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Token/Tokenizer/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function testTokenizeIgnoredViolations(): void
}

/**
* @param array<int, int|string> $expectedTokenTypes
* @param array<int, string> $expectedTokenTypes
*
* @dataProvider tokenizeDataProvider
*/
Expand All @@ -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<array-key, array{string, array<int, int|string>}>
* @return iterable<array-key, array{string, array<int, string>}>
*/
public static function tokenizeDataProvider(): iterable
{
Expand Down