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

OrderableTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseOrderByClause() 0 7 3
A getOptionalOrderByClause() 0 3 2
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