Passed
Push — distinct-support ( f15012 )
by Martin
14:53 queued 10s
created

OrderableTrait::parseOrderByClause()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Traits;
6
7
use Doctrine\ORM\Query\AST\Node;
8
use Doctrine\ORM\Query\AST\OrderByClause;
9
use Doctrine\ORM\Query\Lexer;
10
use Doctrine\ORM\Query\Parser;
11
use Doctrine\ORM\Query\SqlWalker;
12
use Doctrine\ORM\Query\TokenType;
13
use MartinGeorgiev\Utils\DoctrineOrm;
14
15
trait OrderableTrait
16
{
17
    protected Node $expression;
18
19
    protected ?OrderByClause $orderByClause = null;
20
21 2
    protected function parseOrderByClause(Parser $parser): void
22
    {
23 2
        $shouldUseLexer = DoctrineOrm::isPre219();
24 2
        $lexer = $parser->getLexer();
25
26 2
        if ($lexer->isNextToken($shouldUseLexer ? Lexer::T_ORDER : TokenType::T_ORDER)) {
0 ignored issues
show
Bug introduced by
It seems like $shouldUseLexer ? Doctri...uery\TokenType::T_ORDER can also be of type Doctrine\ORM\Query\TokenType; however, parameter $type of Doctrine\Common\Lexer\AbstractLexer::isNextToken() does only seem to accept UnitEnum|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        if ($lexer->isNextToken(/** @scrutinizer ignore-type */ $shouldUseLexer ? Lexer::T_ORDER : TokenType::T_ORDER)) {
Loading history...
Bug introduced by
The constant Doctrine\ORM\Query\Lexer::T_ORDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27 2
            $this->orderByClause = $parser->OrderByClause();
28
        }
29
    }
30
31 2
    protected function getOptionalOrderByClause(SqlWalker $sqlWalker): string
32
    {
33 2
        return $this->orderByClause instanceof OrderByClause ? $this->orderByClause->dispatch($sqlWalker) : '';
34
    }
35
}
36