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

JsonbPathExists   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMinArgumentCount() 0 3 1
A getNodeMappingPattern() 0 3 1
A getMaxArgumentCount() 0 3 1
A validateArguments() 0 7 2
A getFunctionName() 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\Traits\BooleanValidationTrait;
9
10
/**
11
 * Implementation of PostgreSQL JSONB_PATH_EXISTS().
12
 *
13
 * Checks whether the JSON path returns any item for the specified JSON value.
14
 *
15
 * @see https://www.postgresql.org/docs/14/functions-json.html
16
 * @since 3.1
17
 *
18
 * @author Martin Georgiev <[email protected]>
19
 *
20
 * @example Using it in DQL: "SELECT JSONB_PATH_EXISTS(e.jsonbData, '$.a[*] ? (@ > 2)')"
21
 */
22
class JsonbPathExists extends BaseVariadicFunction
23
{
24
    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\...nctions\JsonbPathExists.
Loading history...
25
26 4
    protected function getNodeMappingPattern(): array
27
    {
28 4
        return ['StringPrimary'];
29
    }
30
31 4
    protected function getFunctionName(): string
32
    {
33 4
        return 'jsonb_path_exists';
34
    }
35
36 4
    protected function getMinArgumentCount(): int
37
    {
38 4
        return 2;
39
    }
40
41 4
    protected function getMaxArgumentCount(): int
42
    {
43 4
        return 4;
44
    }
45
46 3
    protected function validateArguments(Node ...$arguments): void
47
    {
48 3
        parent::validateArguments(...$arguments);
49
50
        // Validate that the fourth parameter is a valid boolean if provided
51 2
        if (\count($arguments) === 4) {
52 2
            $this->validateBoolean($arguments[3], $this->getFunctionName());
53
        }
54
    }
55
}
56