Passed
Pull Request — master (#216)
by
unknown
02:53
created

Resultset::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 4
1
<?php namespace Picqer\Financials\Exact\Query;
2
3
class Resultset
4
{
5
    protected $connection;
6
7
    protected $url;
8
9
    protected $class;
10
11
    protected $params;
12
13
    public function __construct($connection, $url, $class, $params)
14
    {
15
        $this->connection = $connection;
16
        $this->url = $url;
17
        $this->class = $class;
18
        $this->params = $params;
19
    }
20
21
    public function next()
22
    {
23
        $result = $this->connection->get($this->url, $params);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $params seems to be never defined.
Loading history...
24
        $this->url = $this->connection->nextUrl;
25
        return $this->collectionFromResult($result, $this->class);
0 ignored issues
show
Unused Code introduced by
The call to Picqer\Financials\Exact\...:collectionFromResult() has too many arguments starting with $this->class. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        return $this->/** @scrutinizer ignore-call */ collectionFromResult($result, $this->class);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
26
    }
27
28
    public function hasMore()
29
    {
30
        return $this->url !== null;
31
    }
32
33
    protected function collectionFromResult($result)
34
    {
35
        // If we have one result which is not an assoc array, make it the first element of an array for the
36
        // collectionFromResult function so we always return a collection from filter
37
        if ((bool) count(array_filter(array_keys($result), 'is_string'))) {
38
            $result = [ $result ];
39
        }
40
41
        $class = $this->class;
42
        $collection = [];
43
44
        foreach ($result as $r) {
45
            $collection[] = new $class($this->connection, $r);
46
        }
47
48
        return $collection;
49
    }
50
}
51