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

XmlAgg   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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