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

Random   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 5
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 6 1
A getSql() 0 13 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