Completed
Push — master ( e6533f...d6c42a )
by Woody
12s
created

functions.php ➔ reference()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Latitude\QueryBuilder;
5
6
function isQuery($value): bool
7
{
8 2
    return $value instanceof Query;
9
}
10
11
function isStatement($value): bool
12
{
13 14
    return $value instanceof Statement;
14
}
15
16
function reference($sql): Statement
17
{
18 14
    if (isStatement($sql)) {
19 2
        return $sql;
20
    }
21
22 12
    if (strpos($sql, ' ') === false) {
23 12
        return Reference::make($sql);
24
    }
25
26 2
    return Alias::make(...\preg_split('/ (?:AS )?/i', $sql));
0 ignored issues
show
Bug introduced by Woody Gilk
The call to make() misses a required argument $alias.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by Woody Gilk
\preg_split('/ (?:AS )?/i', $sql) is of type array, but the function expects a object<Latitude\QueryBuilder\Statement>|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
}
28