Query::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Mnabialek\LaravelSqlLogger;
4
5
use Mnabialek\LaravelSqlLogger\Objects\SqlQuery;
6
use Mnabialek\LaravelVersion\Version;
7
8
class Query
9
{
10
    /**
11
     * @var Version
12
     */
13
    private $version;
14
15
    /**
16
     * Query constructor.
17
     *
18
     * @param Version $version
19
     */
20
    public function __construct(Version $version)
21
    {
22
        $this->version = $version;
23
    }
24
25
    /**
26
     * @param int $number
27
     * @param string|\Illuminate\Database\Events\QueryExecuted $query
28
     * @param array|null $bindings
29
     * @param float|null $time
30
     *
31
     * @return SqlQuery
32
     */
33
    public function get($number, $query, array $bindings = null, $time = null)
34
    {
35
        // for Laravel/Lumen 5.2+ $query is object and it holds all the data
36
        if ($this->version->min('5.2.0')) {
37
            $bindings = $query->bindings;
38
            $time = $query->time;
39
            $query = $query->sql;
40
        }
41
42
        return new SqlQuery($number, $query, $bindings, $time);
0 ignored issues
show
Bug introduced by
It seems like $query can also be of type Illuminate\Database\Events\QueryExecuted; however, parameter $sql of Mnabialek\LaravelSqlLogg...SqlQuery::__construct() does only seem to accept string, 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

42
        return new SqlQuery($number, /** @scrutinizer ignore-type */ $query, $bindings, $time);
Loading history...
Bug introduced by
It seems like $bindings can also be of type null; however, parameter $bindings of Mnabialek\LaravelSqlLogg...SqlQuery::__construct() does only seem to accept array, 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

42
        return new SqlQuery($number, $query, /** @scrutinizer ignore-type */ $bindings, $time);
Loading history...
43
    }
44
}
45