Datetime   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 43
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 9 1
A getSql() 0 8 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\DQL;
10
11
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
12
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression;
13
use Doctrine\ORM\Query\Lexer;
14
use Doctrine\ORM\Query\SqlWalker;
15
use Doctrine\ORM\Query\Parser;
16
17
/**
18
 * Datetime.
19
 *
20
 * Datetime ::= "DATETIME" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
21
 */
22
class Datetime extends FunctionNode
23
{
24
    /**
25
     * First date expression.
26
     *
27
     * @var SimpleArithmeticExpression
28
     */
29
    private $firstDateExpression = null;
30
31
    /**
32
     * Second date expression.
33
     *
34
     * @var SimpleArithmeticExpression
35
     */
36
    private $secondDateExpression = null;
37
38
    /**
39
     * @param Parser $parser
40
     */
41
    public function parse(Parser $parser)
42
    {
43
        $parser->match(Lexer::T_IDENTIFIER);
44
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
45
        $this->firstDateExpression = $parser->ArithmeticPrimary();
46
        $parser->match(Lexer::T_COMMA);
47
        $this->secondDateExpression = $parser->ArithmeticPrimary();
48
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
49
    }
50
51
    /**
52
     * @param SqlWalker $sqlWalker
53
     *
54
     * @return string
55
     */
56
    public function getSql(SqlWalker $sqlWalker)
57
    {
58
        return sprintf(
59
            'DATETIME(%s, %s)',
60
            $this->firstDateExpression->dispatch($sqlWalker),
61
            $this->secondDateExpression->dispatch($sqlWalker)
62
        );
63
    }
64
}
65