Completed
Push — develop ( 18fefe...8c9741 )
by Martin
02:08
created

Greatest::feedParserWithNodes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
4
5
use Doctrine\ORM\Query\Lexer;
6
use Doctrine\ORM\Query\Parser;
7
use Doctrine\ORM\Query\SqlWalker;
8
9
/**
10
 * Implementation of PostgreSql GREATEST()
11
 * @see https://www.postgresql.org/docs/9.4/static/functions-conditional.html#FUNCTIONS-GREATEST-LEAST
12
 *
13
 * @since 0.7
14
 * @author Martin Georgiev <[email protected]>
15
 */
16
class Greatest extends AbstractFunction
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $commonNodeMapping = 'ArithmeticPrimary';
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    protected function customiseFunction()
27
    {
28
        $this->setFunctionPrototype('greatest(%s)');
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function feedParserWithNodes(Parser $parser)
35
    {
36
        $lexer = $parser->getLexer();
37
38
        $this->nodes[] = $parser->{$this->commonNodeMapping}();
39
40
        $aheadType = $lexer->lookahead['type'];
41
        while (Lexer::T_CLOSE_PARENTHESIS !== $aheadType) {
42
            if (Lexer::T_COMMA === $aheadType) {
43
                $parser->match(Lexer::T_COMMA);
44
                $this->nodes[] = $parser->{$this->commonNodeMapping}();
45
            }
46
            $aheadType = $lexer->lookahead['type'];
47
        }
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 View Code Duplication
    public function getSql(SqlWalker $sqlWalker)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $dispatched = [];
56
        foreach ($this->nodes as $node) {
57
            $dispatched[] = $node->dispatch($sqlWalker);
58
        }
59
60
        return sprintf($this->functionPrototype, implode(',', $dispatched));
61
    }
62
}
63