Passed
Push — main ( 6a5ba9...e111dd )
by Martin
12:18
created

JsonbPathMatch::customizeFunction()   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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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\Traits\BooleanValidationTrait;
9
10
/**
11
 * Implementation of PostgreSQL JSONB_PATH_MATCH().
12
 *
13
 * Returns the SQL boolean result of a JSON path predicate check for the specified JSON value.
14
 * This is useful only with predicate check expressions, not SQL-standard JSON path expressions,
15
 * since it will either fail or return NULL if the path result is not a single boolean value.
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 JSONB_PATH_MATCH(e.jsonbData, 'exists($.a[*] ? (@ >= 2 && @ <= 4))')"
23
 */
24
class JsonbPathMatch 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\JsonbPathMatch.
Loading history...
27
28 4
    protected function getNodeMappingPattern(): array
29
    {
30 4
        return ['StringPrimary'];
31
    }
32
33 4
    protected function getFunctionName(): string
34
    {
35 4
        return 'jsonb_path_match';
36
    }
37
38 4
    protected function getMinArgumentCount(): int
39
    {
40 4
        return 2;
41
    }
42
43 4
    protected function getMaxArgumentCount(): int
44
    {
45 4
        return 4;
46
    }
47
48 3
    protected function validateArguments(Node ...$arguments): void
49
    {
50 3
        parent::validateArguments(...$arguments);
51
52
        // Validate that the fourth parameter is a valid boolean if provided
53 2
        if (\count($arguments) === 4) {
54 2
            $this->validateBoolean($arguments[3], $this->getFunctionName());
55
        }
56
    }
57
}
58