Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 26 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ permissions:

jobs:
tests:
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }}"
name: "PHP ${{ matrix.php }} + Doctrine ORM ${{ matrix.doctrine-orm }} + Doctrine Lexer ${{ matrix.doctrine-lexer }}"
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
doctrine-orm: ['2.14', '3.0', 'latest']
doctrine-lexer: ['2.1', '3.0', 'latest']
doctrine-orm: ['2.14', '2.18', '3.0', 'latest']
include:
- php: '8.1'
doctrine-orm: '2.14'
doctrine-lexer: '1.2'
- php: '8.4'
calculate-code-coverage: true
exclude:
- doctrine-orm: '2.14'
doctrine-lexer: '3.0'
- doctrine-orm: '3.0'
doctrine-lexer: '2.1'

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -46,10 +55,24 @@ jobs:
restore-keys: |
${{ runner.os }}-php-

- name: Install composer dependencies
- name: Install Doctrine Lexer dependency
run: |
if [ "${{ matrix.doctrine-lexer }}" == "1.2" ]; then
composer require doctrine/lexer "~1.2" --dev --prefer-dist --no-interaction --no-progress
elif [ "${{ matrix.doctrine-lexer }}" == "2.1" ]; then
composer require doctrine/lexer "~2.1" --dev --prefer-dist --no-interaction --no-progress
elif [ "${{ matrix.doctrine-lexer }}" == "3.0" ]; then
composer require doctrine/lexer "~3.0" --dev --prefer-dist --no-interaction --no-progress
else
composer update --prefer-dist --no-interaction --no-progress
fi

- name: Install Doctrine ORM dependency
run: |
if [ "${{ matrix.doctrine-orm }}" == "2.14" ]; then
composer require doctrine/orm "~2.14" --prefer-dist --no-interaction --no-progress
elif [ "${{ matrix.doctrine-orm }}" == "2.18" ]; then
composer require doctrine/orm "~2.18" --prefer-dist --no-interaction --no-progress
elif [ "${{ matrix.doctrine-orm }}" == "3.0" ]; then
composer require doctrine/orm "~3.0" --prefer-dist --no-interaction --no-progress
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\ORM\Query\TokenType;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\ParserException;
use MartinGeorgiev\Utils\DoctrineLexer;
use MartinGeorgiev\Utils\DoctrineOrm;

/**
Expand All @@ -30,24 +31,24 @@
try {
// @phpstan-ignore-next-line
$this->nodes[] = $parser->{$this->commonNodeMapping}();
if ($lexer->lookahead?->type === null) {
$lookaheadType = DoctrineLexer::getLookaheadType($lexer);
if ($lookaheadType === null) {
throw ParserException::missingLookaheadType();
}
} catch (\Throwable $throwable) {
throw ParserException::withThrowable($throwable);
}

$aheadType = $lexer->lookahead->type;
$shouldUseLexer = DoctrineOrm::isPre219();

while (($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $aheadType) {
if (($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA) === $aheadType) {
while (($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS) !== $lookaheadType) {
if (($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA) === $lookaheadType) {
$parser->match($shouldUseLexer ? Lexer::T_COMMA : TokenType::T_COMMA);

Check failure on line 46 in src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2

Parameter #1 $token of method Doctrine\ORM\Query\Parser::match() expects 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|100|101|102|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255|256, mixed given.
// @phpstan-ignore-next-line
$this->nodes[] = $parser->{$this->commonNodeMapping}();
}

$aheadType = $lexer->lookahead->type;
$lookaheadType = DoctrineLexer::getLookaheadType($lexer);
}

$this->validateArguments($this->nodes);
Expand Down
33 changes: 33 additions & 0 deletions src/MartinGeorgiev/Utils/DoctrineLexer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Utils;

use Doctrine\ORM\Query\Lexer;

/**
* @internal
*/
final class DoctrineLexer
{
public static function isPre200(Lexer $lexer): bool
{
// @phpstan-ignore-next-line
return \is_array($lexer->lookahead);
}

/**
* @return mixed|null
*/
public static function getLookaheadType(Lexer $lexer)
{
if (self::isPre200($lexer)) {
// @phpstan-ignore-next-line
return $lexer->lookahead['type'];
}

// @phpstan-ignore-next-line
return $lexer->lookahead?->type;
}
}
Loading