Passed
Push — main ( 67265c...6a5ba9 )
by Martin
36:25 queued 21:26
created

JsonbPathQuery::getNodeMappingPattern()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\Exception\InvalidArgumentForVariadicFunctionException;
9
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Traits\BooleanValidationTrait;
10
11
/**
12
 * Implementation of PostgreSQL JSONB_PATH_QUERY().
13
 *
14
 * Returns all JSON items returned by the JSON path for the specified JSON value.
15
 * Returns multiple rows, so it's useful when used in a subquery.
16
 *
17
 * @see https://www.postgresql.org/docs/14/functions-json.html
18
 * @since 3.1
19
 *
20
 * @author Martin Georgiev <[email protected]>
21
 *
22
 * @example Using it in DQL: "SELECT e.id FROM Entity e WHERE e.id IN (SELECT JSONB_PATH_QUERY(e2.jsonbData, '$.items[*].id') FROM Entity2 e2)"
23
 */
24
class JsonbPathQuery 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\...unctions\JsonbPathQuery.
Loading history...
27
28 4
    protected function getNodeMappingPattern(): array
29
    {
30 4
        return ['StringPrimary'];
31
    }
32
33 4
    protected function customizeFunction(): void
34
    {
35 4
        $this->setFunctionPrototype('jsonb_path_query(%s)');
36
    }
37
38 4
    protected function validateArguments(Node ...$arguments): void
39
    {
40 4
        $argumentCount = \count($arguments);
41 4
        if ($argumentCount < 2 || $argumentCount > 4) {
42 2
            throw InvalidArgumentForVariadicFunctionException::between('jsonb_path_query', 2, 4);
43
        }
44
45
        // Validate that the fourth parameter is a valid boolean if provided
46 2
        if ($argumentCount === 4) {
47 2
            $this->validateBoolean($arguments[3], 'JSONB_PATH_QUERY');
48
        }
49
    }
50
}
51