Failed Conditions
Push — issue#808 ( 868db7...3c2936 )
by Guilherme
07:23
created

CountIf::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace LoginCidadao\CoreBundle\DQL;
3
4
use Doctrine\ORM\Query\Lexer, Doctrine\ORM\Query\AST\Functions\FunctionNode;
5
6
class CountIf extends FunctionNode
7
{
8
9
    public $var1 = null;
10
11
    public function parse(\Doctrine\ORM\Query\Parser $parser)
12
    {
13
        
14
        $parser->match(Lexer::T_IDENTIFIER); // (2)
15
        $parser->match(Lexer::T_OPEN_PARENTHESIS); // (3)
16
        $this->var1 = $parser->ConditionalExpression();
17
        $parser->match(Lexer::T_CLOSE_PARENTHESIS); // (3)
18
    }
19
20
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
21
    {
22
        return 'count(case when '.$this->var1->dispatch($sqlWalker).' then 1 else null end)'; // (7)
23
    }
24
}