Test Failed
Push — missing-array-and-json-functio... ( 7a0605 )
by Martin
19:55 queued 04:38
created

ArrayToJsonb::validateArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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\Traits\BooleanValidationTrait;
9
10
/**
11
 * Implementation of PostgreSQL ARRAY_TO_JSONB().
12
 *
13
 * Returns the array as a JSONB array. A PostgreSQL multidimensional array becomes a JSONB array of arrays.
14
 * Line feeds will be added between dimension-1 elements if pretty_bool is true.
15
 *
16
 * @see https://www.postgresql.org/docs/17/functions-json.html
17
 * @since 4.0
18
 *
19
 * @author Martin Georgiev <[email protected]>
20
 *
21
 * @example Using it in DQL: "SELECT ARRAY_TO_JSONB(e.textArray) FROM Entity e"
22
 * @example Using it in DQL with pretty_bool: "SELECT ARRAY_TO_JSONB(e.textArray, 'true') FROM Entity e"
23
 */
24
class ArrayToJsonb extends BaseVariadicFunction
25
{
26
    use BooleanValidationTrait;
0 ignored issues
show
Bug introduced by
The trait MartinGeorgiev\Doctrine\...\BooleanValidationTrait requires the property $value which is not provided by MartinGeorgiev\Doctrine\...\Functions\ArrayToJsonb.
Loading history...
27
28 1
    protected function getNodeMappingPattern(): array
29
    {
30 1
        return ['StringPrimary'];
31
    }
32
33 1
    protected function getFunctionName(): string
34
    {
35 1
        return 'array_to_jsonb';
36
    }
37
38 1
    protected function getMinArgumentCount(): int
39
    {
40 1
        return 1;
41
    }
42
43 1
    protected function getMaxArgumentCount(): int
44
    {
45 1
        return 2;
46
    }
47
48 1
    protected function validateArguments(Node ...$arguments): void
49
    {
50 1
        parent::validateArguments(...$arguments);
51
52
        // Validate that the second parameter is a valid boolean if provided
53 1
        if (\count($arguments) === 2) {
54 1
            $this->validateBoolean($arguments[1], $this->getFunctionName());
55
        }
56
    }
57
}
58
59