Completed
Pull Request — master (#8105)
by
unknown
10:29
created

LocateFunction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 50
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSql() 0 8 2
A parse() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query\AST\Functions;
6
7
use Doctrine\ORM\Query\AST\Node;
8
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression;
9
use Doctrine\ORM\Query\Lexer;
10
use Doctrine\ORM\Query\Parser;
11
use Doctrine\ORM\Query\SqlWalker;
12
13
/**
14
 * "LOCATE" "(" StringPrimary "," StringPrimary ["," SimpleArithmeticExpression]")"
15
 */
16
class LocateFunction extends FunctionNode
17
{
18
    /** @var Node */
19
    public $firstStringPrimary;
20
21
    /** @var Node */
22
    public $secondStringPrimary;
23
24
    /** @var SimpleArithmeticExpression|bool */
25
    public $simpleArithmeticExpression = false;
26
27
    /**
28
     * @override
29
     * @inheritdoc
30
     */
31
    public function getSql(SqlWalker $sqlWalker)
32
    {
33
        return $sqlWalker->getConnection()->getDatabasePlatform()->getLocateExpression(
34
            $sqlWalker->walkStringPrimary($this->secondStringPrimary), // its the other way around in platform
35
            $sqlWalker->walkStringPrimary($this->firstStringPrimary),
36
            ($this->simpleArithmeticExpression
0 ignored issues
show
Bug introduced by
It seems like $this->simpleArithmeticE...eticExpression) : false can also be of type string; however, parameter $startPos of Doctrine\DBAL\Platforms\...::getLocateExpression() does only seem to accept false|integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            /** @scrutinizer ignore-type */ ($this->simpleArithmeticExpression
Loading history...
37
                ? $sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression)
38
                : false
39
            )
40
        );
41
    }
42
43
    /**
44
     * @override
45
     * @inheritdoc
46
     */
47
    public function parse(Parser $parser)
48
    {
49
        $parser->match(Lexer::T_IDENTIFIER);
50
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
51
52
        $this->firstStringPrimary = $parser->StringPrimary();
53
54
        $parser->match(Lexer::T_COMMA);
55
56
        $this->secondStringPrimary = $parser->StringPrimary();
57
58
        $lexer = $parser->getLexer();
59
        if ($lexer->isNextToken(Lexer::T_COMMA)) {
60
            $parser->match(Lexer::T_COMMA);
61
62
            $this->simpleArithmeticExpression = $parser->SimpleArithmeticExpression();
63
        }
64
65
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
66
    }
67
}
68