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

DateSubtract::validateArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 7
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_SUBTRACT().
12
 *
13
 * Subtracts an interval from 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_SUBTRACT(e.timestampWithTz, '1 day', 'Europe/Sofia') FROM Entity e"
22
 */
23
class DateSubtract 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\...\Functions\DateSubtract.
Loading history...
26
27
    protected function getNodeMappingPattern(): array
28
    {
29
        return ['StringPrimary'];
30
    }
31
32
    protected function getFunctionName(): string
33
    {
34
        return 'date_subtract';
35
    }
36
37
    protected function getMinArgumentCount(): int
38
    {
39
        return 2;
40
    }
41
42
    protected function getMaxArgumentCount(): int
43
    {
44
        return 3;
45
    }
46
47
    protected function validateArguments(Node ...$arguments): void
48
    {
49
        parent::validateArguments(...$arguments);
50
51
        // Validate that the third parameter is a valid timezone if provided
52
        if (\count($arguments) === 3) {
53
            $this->validateTimezone($arguments[2], $this->getFunctionName());
54
        }
55
    }
56
}
57