JsonbBuildObject   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getNodeMappingPattern() 0 3 1
A validateArguments() 0 6 2
A getMinArgumentCount() 0 3 1
A getFunctionName() 0 3 1
A getMaxArgumentCount() 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 JSONB_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 JsonbBuildObject extends BaseVariadicFunction
19
{
20 2
    protected function getNodeMappingPattern(): array
21
    {
22 2
        return ['StringPrimary'];
23
    }
24
25 2
    protected function getFunctionName(): string
26
    {
27 2
        return 'jsonb_build_object';
28
    }
29
30 2
    protected function getMinArgumentCount(): int
31
    {
32 2
        return 2; // At least one key-value pair
33
    }
34
35 2
    protected function getMaxArgumentCount(): int
36
    {
37 2
        return PHP_INT_MAX; // No upper limit, but must be even
38
    }
39
40 2
    protected function validateArguments(Node ...$arguments): void
41
    {
42 2
        parent::validateArguments(...$arguments);
43
44 2
        if (\count($arguments) % 2 !== 0) {
45 1
            throw InvalidArgumentForVariadicFunctionException::evenNumber($this->getFunctionName());
46
        }
47
    }
48
}
49