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

RowToJson   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A validateArguments() 0 7 2
A getMinArgumentCount() 0 3 1
A getFunctionName() 0 3 1
A getMaxArgumentCount() 0 3 1
A getNodeMappingPattern() 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 ROW_TO_JSON().
12
 *
13
 * Returns the row as a JSON object. Line feeds will be added between level-1 elements if pretty_bool is true.
14
 *
15
 * @see https://www.postgresql.org/docs/16/functions-json.html
16
 * @since 0.10
17
 *
18
 * @author Martin Georgiev <[email protected]>
19
 *
20
 * @example Using it in DQL: "SELECT ROW_TO_JSON(e.row) FROM Entity e"
21
 * @example Using it in DQL with pretty_bool: "SELECT ROW_TO_JSON(e.row, 'true') FROM Entity e"
22
 */
23
class RowToJson 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\...AST\Functions\RowToJson.
Loading history...
26
27 3
    protected function getNodeMappingPattern(): array
28
    {
29 3
        return ['StringPrimary'];
30
    }
31
32 3
    protected function getFunctionName(): string
33
    {
34 3
        return 'row_to_json';
35
    }
36
37 3
    protected function getMinArgumentCount(): int
38
    {
39 3
        return 1;
40
    }
41
42 3
    protected function getMaxArgumentCount(): int
43
    {
44 3
        return 2;
45
    }
46
47 2
    protected function validateArguments(Node ...$arguments): void
48
    {
49 2
        parent::validateArguments(...$arguments);
50
51
        // Validate that the second parameter is a valid boolean if provided
52 2
        if (\count($arguments) === 2) {
53 2
            $this->validateBoolean($arguments[1], $this->getFunctionName());
54
        }
55
    }
56
}
57