Skip to content

Commit 46069d2

Browse files
Add more Lexer utils for managing versions
1 parent 786fe00 commit 46069d2

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

ci/rector/config.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
56
use Rector\Config\RectorConfig;
67
use Rector\Doctrine\Set\DoctrineSetList;
78
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
@@ -40,6 +41,9 @@
4041

4142
$rectorConfig->skip([
4243
RenamePropertyToMatchTypeRector::class,
44+
FlipTypeControlToUseExclusiveTypeRector::class => [
45+
$basePath.'src/MartinGeorgiev/Utils/DoctrineLexer.php',
46+
],
4347
]);
4448

4549
$rectorConfig->importShortClasses(false);

src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Cast.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
66

7-
use Doctrine\Common\Lexer\Token;
87
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
98
use Doctrine\ORM\Query\AST\Node;
109
use Doctrine\ORM\Query\Lexer;
1110
use Doctrine\ORM\Query\Parser;
1211
use Doctrine\ORM\Query\SqlWalker;
1312
use Doctrine\ORM\Query\TokenType;
13+
use MartinGeorgiev\Utils\DoctrineLexer;
1414
use MartinGeorgiev\Utils\DoctrineOrm;
1515

1616
/**
@@ -40,16 +40,11 @@ public function parse(Parser $parser): void
4040
$parser->match($shouldUseLexer ? Lexer::T_IDENTIFIER : TokenType::T_IDENTIFIER);
4141

4242
$lexer = $parser->getLexer();
43-
$token = $lexer->token;
44-
if (!$token instanceof Token) {
43+
$type = DoctrineLexer::getTokenValue($lexer);
44+
if ($type === null) {
4545
return;
4646
}
4747

48-
if (!\is_string($token->value)) {
49-
return;
50-
}
51-
52-
$type = $token->value;
5348
if ($lexer->isNextToken($shouldUseLexer ? Lexer::T_OPEN_PARENTHESIS : TokenType::T_OPEN_PARENTHESIS)) {
5449
$parser->match($shouldUseLexer ? Lexer::T_OPEN_PARENTHESIS : TokenType::T_OPEN_PARENTHESIS);
5550
$parameter = $parser->Literal();

src/MartinGeorgiev/Utils/DoctrineLexer.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,23 @@ public static function getLookaheadType(Lexer $lexer)
3636
// @phpstan-ignore-next-line
3737
return $lexer->lookahead?->type;
3838
}
39+
40+
/**
41+
* @return mixed|null
42+
*/
43+
public static function getTokenValue(Lexer $lexer)
44+
{
45+
if (self::isPre200($lexer)) {
46+
// @phpstan-ignore-next-line
47+
if ($lexer->token === null) {
48+
return null;
49+
}
50+
51+
// @phpstan-ignore-next-line
52+
return $lexer->token['value'];
53+
}
54+
55+
// @phpstan-ignore-next-line
56+
return $lexer->token?->value;
57+
}
3958
}

0 commit comments

Comments
 (0)