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

DateAdd::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\TimezoneValidationTrait;
9
10
/**
11
 * Implementation of PostgreSQL DATE_ADD().
12
 *
13
 * Adds an interval to a timestamp with time zone, computing times of day and daylight-savings
14
 * adjustments according to the time zone.
15
 *
16
 * @see https://www.postgresql.org/docs/16/functions-datetime.html
17
 * @since 3.1
18
 *
19
 * @author Martin Georgiev <[email protected]>
20
 *
21
 * @example Using it in DQL: "SELECT DATE_ADD(e.timestampWithTz, '1 day', 'Europe/Sofia') FROM Entity e"
22
 */
23
class DateAdd extends BaseVariadicFunction
24
{
25
    use TimezoneValidationTrait;
0 ignored issues
show
Bug introduced by
The trait MartinGeorgiev\Doctrine\...TimezoneValidationTrait requires the property $value which is not provided by MartinGeorgiev\Doctrine\...y\AST\Functions\DateAdd.
Loading history...
26
27 4
    protected function getNodeMappingPattern(): array
28
    {
29 4
        return ['StringPrimary'];
30
    }
31
32 4
    protected function getFunctionName(): string
33
    {
34 4
        return 'date_add';
35
    }
36
37 4
    protected function getMinArgumentCount(): int
38
    {
39 4
        return 2;
40
    }
41
42 4
    protected function getMaxArgumentCount(): int
43
    {
44 4
        return 3;
45
    }
46
47 3
    protected function validateArguments(Node ...$arguments): void
48
    {
49 3
        parent::validateArguments(...$arguments);
50
51
        // Validate that the third parameter is a valid timezone if provided
52 2
        if (\count($arguments) === 3) {
53 2
            $this->validateTimezone($arguments[2], $this->getFunctionName());
54
        }
55
    }
56
}
57