Completed
Pull Request — develop (#29)
by Martin
01:59
created

BaseComparisonFunction::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
declare(strict_types=1);
4
5
namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\Lexer;
8
use Doctrine\ORM\Query\Parser;
9
use Doctrine\ORM\Query\SqlWalker;
10
11
/**
12
 * @since 1.0
13
 * @author Martin Georgiev <[email protected]>
14
 */
15
abstract class BaseComparisonFunction extends BaseFunction
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $commonNodeMapping = 'ArithmeticPrimary';
21
22
    public function feedParserWithNodes(Parser $parser): void
23
    {
24
        $lexer = $parser->getLexer();
25
26
        $this->nodes[] = $parser->{$this->commonNodeMapping}();
27
28
        $aheadType = $lexer->lookahead['type'];
29
        while (Lexer::T_CLOSE_PARENTHESIS !== $aheadType) {
30
            if (Lexer::T_COMMA === $aheadType) {
31
                $parser->match(Lexer::T_COMMA);
32
                $this->nodes[] = $parser->{$this->commonNodeMapping}();
33
            }
34
            $aheadType = $lexer->lookahead['type'];
35
        }
36
    }
37
38 View Code Duplication
    public function getSql(SqlWalker $sqlWalker): string
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...
39
    {
40
        $dispatched = [];
41
        foreach ($this->nodes as $node) {
42
            $dispatched[] = $node->dispatch($sqlWalker);
43
        }
44
45
        return sprintf($this->functionPrototype, implode(',', $dispatched));
46
    }
47
}
48