IfElse::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Luxifer\DQL\String;
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
 * ConcatWsFunction ::= "IF" "(" ConditionalExpression "," ArithmeticExpression "," ArithmeticExpression ")"
12
 */
13
class IfElse extends FunctionNode
14
{
15
    public $condition;
16
    public $isTrueStatement;
17
    public $isFalseStatement;
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->condition = $parser->ConditionalExpression();
24
25 1
        $parser->match(Lexer::T_COMMA);
26 1
        $this->isTrueStatement = $parser->ArithmeticExpression();
27
28 1
        $parser->match(Lexer::T_COMMA);
29 1
        $this->isFalseStatement = $parser->ArithmeticExpression();
30
31 1
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
32 1
    }
33
34 1
    public function getSql(SqlWalker $sqlWalker)
35
    {
36
        return 'IF(' .
37 1
            $this->condition->dispatch($sqlWalker) . ', ' .
38 1
            $this->isTrueStatement->dispatch($sqlWalker) . ', ' .
39 1
            $this->isFalseStatement->dispatch($sqlWalker) .
40 1
        ')';
41
    }
42
}
43