Passed
Pull Request — master (#69)
by Martin
08:30
created

BaseVariadicFunction::feedParserWithNodes()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.6333
cc 4
nc 4
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
 * @author Martin Georgiev <[email protected]>
13
 */
14
abstract class BaseVariadicFunction extends BaseFunction
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $commonNodeMapping = 'StringPrimary';
20
21
    public function feedParserWithNodes(Parser $parser): void
22
    {
23
        $lexer = $parser->getLexer();
24
25
        $this->nodes[] = $parser->{$this->commonNodeMapping}();
26
        if (!isset($lexer->lookahead['type'])) {
27
            throw new \RuntimeException('The parser\'s "lookahead" property is not populated with a type');
28
        }
29
30
        $aheadType = $lexer->lookahead['type'];
31
32
        while (Lexer::T_CLOSE_PARENTHESIS !== $aheadType) {
33
            if (Lexer::T_COMMA === $aheadType) {
34
                $parser->match(Lexer::T_COMMA);
35
                $this->nodes[] = $parser->{$this->commonNodeMapping}();
36
            }
37
            $aheadType = $lexer->lookahead['type'];
38
        }
39
    }
40
41 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...
42
    {
43
        $dispatched = [];
44
        foreach ($this->nodes as $node) {
45
            $dispatched[] = $node->dispatch($sqlWalker);
46
        }
47
48
        return \sprintf($this->functionPrototype, \implode(', ', $dispatched));
49
    }
50
}
51