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

ArrayAgg   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A customizeFunction() 0 4 1
A getSql() 0 9 1
A parse() 0 15 4
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
 * Implementation of PostgreSQL ARRAY_AGG().
17
 *
18
 * @see https://www.postgresql.org/docs/17/functions-aggregate.html
19
 * @since 1.4
20
 *
21
 * @author Martin Georgiev <[email protected]>
22
 */
23
class ArrayAgg extends BaseFunction
24
{
25
    use OrderableTrait;
26
    use DistinctableTrait;
27
28 1
    protected function customizeFunction(): void
29
    {
30 1
        $this->setFunctionPrototype('array_agg(%s%s%s)');
31 1
        $this->addNodeMapping('StringPrimary');
32
    }
33
34 1
    public function parse(Parser $parser): void
35
    {
36 1
        $shouldUseLexer = DoctrineOrm::isPre219();
37
38 1
        $this->customizeFunction();
39
40 1
        $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...
41 1
        $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...
42
43 1
        $this->parseDistinctClause($parser);
44 1
        $this->expression = $parser->StringPrimary();
45
46 1
        $this->parseOrderByClause($parser);
47
48 1
        $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...
49
    }
50
51 1
    public function getSql(SqlWalker $sqlWalker): string
52
    {
53 1
        $dispatched = [
54 1
            $this->getOptionalDistinctClause(),
55 1
            $this->expression->dispatch($sqlWalker),
56 1
            $this->getOptionalOrderByClause($sqlWalker),
57 1
        ];
58
59 1
        return \vsprintf($this->functionPrototype, $dispatched);
60
    }
61
}
62