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

Format::getSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
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