Completed
Push — master ( 5e4125...dc8d59 )
by Jonathan André
15:32
created

Format   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 48
rs 10
c 2
b 1
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSql() 0 8 1
A parse() 0 11 1
1
<?php
2
3
namespace Bludata\Doctrine\ORM\CustomFunctions\String;
4
5
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
6
use Doctrine\ORM\Query\Lexer;
7
8
class Format extends FunctionNode
9
{
10
    /*
11
     * holds the timestamp of the DATE_FORMAT DQL statement
12
     * @var mixed
13
     */
14
    protected $dateExpression;
15
16
    /**
17
     * holds the '%format' parameter of the DATE_FORMAT DQL statement.
18
     *
19
     * @var string
20
     */
21
    protected $formatChar;
22
23
    /**
24
     * getSql - allows ORM  to inject a DATE_FORMAT() statement into an SQL string being constructed.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 101 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
25
     *
26
     * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
27
     *
28
     * @return void
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
29
     */
30
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
31
    {
32
        return 'FORMAT('.
33
                $sqlWalker->walkArithmeticExpression($this->dateExpression).
34
                ','.
35
                $sqlWalker->walkStringPrimary($this->formatChar).
36
                ')';
37
    }
38
39
    /**
40
     * parse - allows DQL to breakdown the DQL string into a processable structure.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 83 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
41
     *
42
     * @param \Doctrine\ORM\Query\Parser $parser
43
     */
44
    public function parse(\Doctrine\ORM\Query\Parser $parser)
45
    {
46
        $parser->match(Lexer::T_IDENTIFIER);
47
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
48
49
        $this->dateExpression = $parser->ArithmeticExpression();
50
        $parser->match(Lexer::T_COMMA);
51
52
        $this->formatChar = $parser->StringPrimary();
53
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
54
    }
55
}
56