Completed
Push — master ( 0fd562...096c68 )
by Rémi
03:14
created

Random::getSql()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
crap 3
1
<?php
2
namespace Doctrine\Tools;
3
4
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
5
use Doctrine\ORM\Query\Lexer;
6
use Doctrine\ORM\Query\Parser;
7
use Doctrine\ORM\Query\QueryException;
8
use Doctrine\ORM\Query\SqlWalker;
9
10
class Random extends FunctionNode
11
{
12
    /**
13
     * @param Parser $parser
14
     */
15 9
    public function parse(Parser $parser)
16
    {
17 9
        $parser->match(Lexer::T_IDENTIFIER);
18 9
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
19 9
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
20 9
    }
21
22
    /**
23
     * @param  SqlWalker $sqlWalker
24
     * @return string
25
     * @throws QueryException
26
     */
27 9
    public function getSql(SqlWalker $sqlWalker)
28
    {
29 9
        switch ($sqlWalker->getConnection()->getDatabasePlatform()->getName()) {
30 9
            case 'postgresql':
31 3
                return 'RANDOM()';
32
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
33 6
            case 'mysql':
34 3
                return 'RAND()';
35
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
36 2
            default:
37 3
                throw new QueryException("You can't use RANDOM()!");
38 2
        }
39
    }
40
}
41