GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Query::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 2
nc 2
nop 1
1
<?php
2
3
namespace duxet\Rethinkdb;
4
5
use r;
6
7
class Query
8
{
9
    /**
10
     * The connection instance.
11
     *
12
     * @var Connection
13
     */
14
    protected $connection;
15
16
    /**
17
     * The \r\ValuedQuery instance.
18
     *
19
     * @var \r\ValuedQuery
20
     */
21
    protected $query;
22
23
    /**
24
     * Constructor.
25
     *
26
     * @param Connection $connection
27
     */
28
    public function __construct(Connection $connection)
29
    {
30
        $this->connection = $connection;
31
        $this->query = r\Db($connection->getDatabaseName());
0 ignored issues
show
Documentation Bug introduced by
It seems like \r\Db($connection->getDatabaseName()) of type object<r\Queries\Dbs\Db> is incompatible with the declared type object<r\ValuedQuery> of property $query.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
    }
33
34
    /**
35
     * Handle dynamic method calls.
36
     *
37
     * @param string $method
38
     * @param array  $parameters
39
     *
40
     * @return mixed
41
     */
42
    public function __call($method, $parameters)
43
    {
44
        $autoRun = ['count', 'sum', 'insert'];
45
46
        $query = call_user_func_array([$this->query, $method], $parameters);
47
48
        if (in_array($method, $autoRun)) {
49
            return $this->run($query);
50
        }
51
52
        $this->query = $query;
53
54
        return $this;
55
    }
56
57
    public function run($query = null)
58
    {
59
        $start = microtime(true);
60
        $query = $query ?: $this->query;
61
62
        $connection = $this->connection->getConnection();
63
        $result = $query->run($connection);
64
65
        $query = strval($this->query);
66
        $time = $this->connection->getElapsedTime($start);
67
        $this->connection->logQuery($query, [], $time);
68
69
        return $this->nativeArray($result);
70
    }
71
72
    private function nativeArray($val)
73
    {
74
        if (is_array($val)) {
75
            foreach ($val as $k => $v) {
76
                $val[$k] = $this->nativeArray($v);
77
            }
78
79
            return $val;
80
        } elseif (is_object($val) && $val instanceof \ArrayObject) {
81
            return $val->getArrayCopy();
82
        } else {
83
            return $val;
84
        }
85
    }
86
}
87