Failed Conditions
Pull Request — develop (#6935)
by Michael
167:08 queued 149:28
created

LocateFunction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 4

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\Lexer;
8
9
/**
10
 * "LOCATE" "(" StringPrimary "," StringPrimary ["," SimpleArithmeticExpression]")"
11
 *
12
 * 
13
 * @link    www.doctrine-project.org
14
 * @since   2.0
15
 * @author  Guilherme Blanco <[email protected]>
16
 * @author  Jonathan Wage <[email protected]>
17
 * @author  Roman Borschel <[email protected]>
18
 * @author  Benjamin Eberlei <[email protected]>
19
 */
20
class LocateFunction extends FunctionNode
21
{
22
    public $firstStringPrimary;
23
    public $secondStringPrimary;
24
25
    /**
26
     * @var \Doctrine\ORM\Query\AST\SimpleArithmeticExpression|bool
27
     */
28
    public $simpleArithmeticExpression = false;
29
30
    /**
31
     * @override
32
     * @inheritdoc
33
     */
34 1
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
35
    {
36 1
        return $sqlWalker->getConnection()->getDatabasePlatform()->getLocateExpression(
37 1
            $sqlWalker->walkStringPrimary($this->secondStringPrimary), // its the other way around in platform
38 1
            $sqlWalker->walkStringPrimary($this->firstStringPrimary),
39 1
            (($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 integer|boolean, 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

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