Test Failed
Push — renovate/major-composer-qa-too... ( 9595c4...d17b72 )
by
unknown
13:07
created

JsonbPathQueryFirst   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

5 Methods

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