Passed
Push — array_agg-and-order_by ( 4a69e9 )
by Martin
03:10
created

ArrayAgg   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 20
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A customiseFunction() 0 3 1
A getSql() 0 8 1
A parseFunction() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\Parser;
8
use Doctrine\ORM\Query\SqlWalker;
9
10
/**
11
 * Implementation of PostgreSql ARRAY_AGG().
12
 *
13
 * @see https://www.postgresql.org/docs/17/functions-aggregate.html
14
 * @since 1.4
15
 *
16
 * @author Martin Georgiev <[email protected]>
17
 */
18
class ArrayAgg extends BaseOrderableFunction
19
{
20
    protected function customiseFunction(): void
21
    {
22
        $this->setFunctionPrototype('array_agg(%s%s)');
23
    }
24
25
    protected function parseFunction(Parser $parser): void
26
    {
27
        $this->expression = $parser->StringPrimary();
28
    }
29
30
    public function getSql(SqlWalker $sqlWalker): string
31
    {
32
        $dispatched = [
33
            $this->expression->dispatch($sqlWalker),
34
            $this->getOptionalOrderByClause($sqlWalker),
35
        ];
36
37
        return \vsprintf($this->functionPrototype, $dispatched);
38
    }
39
}
40