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

DistinctableTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 1
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptionalDistinctClause() 0 3 2
A parseDistinctClause() 0 8 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Traits;
6
7
use Doctrine\ORM\Query\Lexer;
8
use Doctrine\ORM\Query\Parser;
9
use Doctrine\ORM\Query\TokenType;
10
use MartinGeorgiev\Utils\DoctrineOrm;
11
12
trait DistinctableTrait
13
{
14
    protected bool $isDistinct = false;
15
16 2
    protected function parseDistinctClause(Parser $parser): void
17
    {
18 2
        $shouldUseLexer = DoctrineOrm::isPre219();
19 2
        $lexer = $parser->getLexer();
20
21 2
        if ($lexer->isNextToken($shouldUseLexer ? Lexer::T_DISTINCT : TokenType::T_DISTINCT)) {
0 ignored issues
show
Bug introduced by
The constant Doctrine\ORM\Query\Lexer::T_DISTINCT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
It seems like $shouldUseLexer ? Doctri...y\TokenType::T_DISTINCT 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

21
        if ($lexer->isNextToken(/** @scrutinizer ignore-type */ $shouldUseLexer ? Lexer::T_DISTINCT : TokenType::T_DISTINCT)) {
Loading history...
22 2
            $parser->match($shouldUseLexer ? Lexer::T_DISTINCT : TokenType::T_DISTINCT);
23 2
            $this->isDistinct = true;
24
        }
25
    }
26
27 2
    protected function getOptionalDistinctClause(): string
28
    {
29 2
        return $this->isDistinct ? 'DISTINCT ' : '';
30
    }
31
}
32