Month   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 17
loc 17
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 7 7 1
A getSql() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace KI\CoreBundle\DQL;
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
 * Date ::= "HOUR" "("ArithmeticPrimary")"
12
 */
13 View Code Duplication
class Month extends FunctionNode
14
{
15
    public $dateExpression;
16
17
    public function parse(Parser $parser)
18
    {
19
        $parser->match(Lexer::T_IDENTIFIER);
20
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
21
        $this->dateExpression = $parser->ArithmeticPrimary();
22
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
23
    }
24
25
    public function getSql(SqlWalker $sqlWalker)
26
    {
27
        return 'MONTH(FROM_UNIXTIME('.$this->dateExpression->dispatch($sqlWalker).'))';
28
    }
29
}
30