Passed
Push — main ( 01b564...5ff908 )
by Martin
44:06 queued 29:08
created

DateTrunc   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
c 1
b 0
f 1
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getMinArgumentCount() 0 3 1
A getNodeMappingPattern() 0 3 1
A getFunctionName() 0 3 1
A getMaxArgumentCount() 0 3 1
A validateArguments() 0 7 2
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_TRUNC().
12
 *
13
 * @see https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
14
 * @since 3.7
15
 *
16
 * @author Jan Klan <[email protected]>
17
 *
18
 * @example Using it in DQL: "SELECT DATE_TRUNC('day', e.timestampWithTz, 'Australia/Adelaide') FROM Entity e"
19
 */
20
class DateTrunc extends BaseVariadicFunction
21
{
22
    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\...AST\Functions\DateTrunc.
Loading history...
23
24 7
    protected function getNodeMappingPattern(): array
25
    {
26 7
        return ['StringPrimary'];
27
    }
28
29 7
    protected function getFunctionName(): string
30
    {
31 7
        return 'date_trunc';
32
    }
33
34 7
    protected function getMinArgumentCount(): int
35
    {
36 7
        return 2;
37
    }
38
39 7
    protected function getMaxArgumentCount(): int
40
    {
41 7
        return 3;
42
    }
43
44 6
    protected function validateArguments(Node ...$arguments): void
45
    {
46 6
        parent::validateArguments(...$arguments);
47
48
        // Validate that the third parameter is a valid timezone if provided
49 5
        if (\count($arguments) === 3) {
50 5
            $this->validateTimezone($arguments[2], $this->getFunctionName());
51
        }
52
    }
53
}
54