Passed
Push — main ( c866ae...0b4db8 )
by Martin
13:26
created

BaseAggregateFunction::parse()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 15
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\Lexer;
8
use Doctrine\ORM\Query\Parser;
9
use Doctrine\ORM\Query\SqlWalker;
10
use Doctrine\ORM\Query\TokenType;
11
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Traits\DistinctableTrait;
12
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Traits\OrderableTrait;
13
use MartinGeorgiev\Utils\DoctrineOrm;
14
15
/**
16
 * @since 3.0
17
 *
18
 * @author Martin Georgiev <[email protected]>
19
 */
20
abstract class BaseAggregateFunction extends BaseFunction
21
{
22
    use OrderableTrait;
23
    use DistinctableTrait;
24
25 3
    public function parse(Parser $parser): void
26
    {
27 3
        $shouldUseLexer = DoctrineOrm::isPre219();
28
29 3
        $this->customizeFunction();
30
31 3
        $parser->match($shouldUseLexer ? Lexer::T_IDENTIFIER : TokenType::T_IDENTIFIER);
0 ignored issues
show
Bug introduced by
The constant Doctrine\ORM\Query\Lexer::T_IDENTIFIER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
32 3
        $parser->match($shouldUseLexer ? Lexer::T_OPEN_PARENTHESIS : TokenType::T_OPEN_PARENTHESIS);
0 ignored issues
show
Bug introduced by
The constant Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
34 3
        $this->parseDistinctClause($parser);
35 3
        $this->expression = $parser->StringPrimary();
36
37 3
        $this->parseOrderByClause($parser);
38
39 3
        $parser->match($shouldUseLexer ? Lexer::T_CLOSE_PARENTHESIS : TokenType::T_CLOSE_PARENTHESIS);
0 ignored issues
show
Bug introduced by
The constant Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
40
    }
41
42 3
    public function getSql(SqlWalker $sqlWalker): string
43
    {
44 3
        $dispatched = [
45 3
            $this->getOptionalDistinctClause(),
46 3
            $this->expression->dispatch($sqlWalker),
47 3
            $this->getOptionalOrderByClause($sqlWalker),
48 3
        ];
49
50 3
        return \vsprintf($this->functionPrototype, $dispatched);
51
    }
52
}
53