Passed
Pull Request — main (#349)
by Martin
25:23 queued 10:22
created

JsonBuildObject   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateArguments() 0 5 3
A getNodeMappingPattern() 0 3 1
A customizeFunction() 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\AST\Node;
8
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
9
10
/**
11
 * Implementation of PostgreSQL JSON_BUILD_OBJECT().
12
 *
13
 * @see https://www.postgresql.org/docs/17/functions-json.html
14
 * @since 2.9
15
 *
16
 * @author Martin Georgiev <[email protected]>
17
 */
18
class JsonBuildObject extends BaseVariadicFunction
19
{
20 2
    protected function getNodeMappingPattern(): array
21
    {
22 2
        return ['StringPrimary'];
23
    }
24
25 2
    protected function customizeFunction(): void
26
    {
27 2
        $this->setFunctionPrototype('json_build_object(%s)');
28
    }
29
30 2
    protected function validateArguments(Node ...$arguments): void
31
    {
32 2
        $argumentCount = \count($arguments);
33 2
        if ($argumentCount === 0 || $argumentCount % 2 !== 0) {
34 1
            throw InvalidArgumentForVariadicFunctionException::evenNumber('json_build_object');
35
        }
36
    }
37
}
38