Passed
Pull Request — main (#493)
by
unknown
12:20
created

InvalidTruncFieldException::forInvalidField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception;
6
7
use Doctrine\DBAL\Types\ConversionException;
8
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\DateTrunc;
9
10
/**
11
 * @since 3.7
12
 *
13
 * @author Jan Klan <[email protected]>
14
 */
15
class InvalidTruncFieldException extends ConversionException
16
{
17
    public static function forNonLiteralNode(string $nodeClass, string $functionName): self
18
    {
19
        return new self(\sprintf(
20
            'The date_trunc field parameter for %s must be a string literal, got %s',
21
            $functionName,
22
            $nodeClass
23
        ));
24
    }
25
26 4
    public static function forInvalidField(string $timezone, string $functionName): self
27
    {
28 4
        return new self(\sprintf(
29 4
            'Invalid date_trunc field value "%s" provided for %s. Must be one of: %s.',
30 4
            $timezone,
31 4
            $functionName,
32 4
            \implode(', ', DateTrunc::FIELDS)
33 4
        ));
34
    }
35
}
36