Completed
Push — master ( 8da333...8f94e6 )
by Kamil
05:27 queued 12s
created

DateFormat::getSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\CoreBundle\Doctrine\DQL;
15
16
use Doctrine\ORM\Query\AST\ArithmeticExpression;
17
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
18
use Doctrine\ORM\Query\Lexer;
19
use Doctrine\ORM\Query\Parser;
20
use Doctrine\ORM\Query\SqlWalker;
21
22
final class DateFormat extends FunctionNode
23
{
24
    /** @var ArithmeticExpression|null  */
25
    public $date = null;
26
    /** @var ArithmeticExpression|null  */
27
    public $pattern = null;
28
29
    public function parse(Parser $parser)
30
    {
31
        $parser->match(Lexer::T_IDENTIFIER);
32
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
33
        $this->date = $parser->ArithmeticExpression();
34
        $parser->match(Lexer::T_COMMA);
35
        $this->pattern = $parser->StringPrimary();
36
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
37
    }
38
39
    public function getSql(SqlWalker $sqlWalker)
40
    {
41
        return sprintf('DATE_FORMAT(%s, %s)', $this->date->dispatch($sqlWalker), $this->pattern->dispatch($sqlWalker));
42
    }
43
}
44