DateDiff::getSql()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Luxifer\DQL\Datetime;
4
5
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
6
use Doctrine\ORM\Query\Lexer;
7
use Doctrine\ORM\Query\Parser;
8
use Doctrine\ORM\Query\SqlWalker;
9
10
/**
11
 * DateFunction ::= "DATEDIFF" "(" ArithmeticPrimary "," ArithmeticPrimary ")"
12
 * @author Florent Viel <[email protected]>
13
 */
14
class DateDiff extends FunctionNode
15
{
16
    public $firstDateExpression;
17
    public $secondDateExpression;
18
19 1
    public function parse(Parser $parser)
20
    {
21 1
        $parser->match(Lexer::T_IDENTIFIER);
22 1
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
23 1
        $this->firstDateExpression = $parser->ArithmeticPrimary();
24 1
        $parser->match(Lexer::T_COMMA);
25 1
        $this->secondDateExpression = $parser->ArithmeticPrimary();
26 1
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
27 1
    }
28
29 1
    public function getSql(SqlWalker $sqlWalker)
30
    {
31
        return 'DATEDIFF(' .
32 1
            $this->firstDateExpression->dispatch($sqlWalker) . ', ' .
33 1
            $this->secondDateExpression->dispatch($sqlWalker) .
34 1
        ')';
35
    }
36
}
37