Completed
Push — master ( a93b08...8d3934 )
by Stephan
02:44 queued 46s
created

Resultset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A next() 0 6 1
A hasMore() 0 3 1
A collectionFromResult() 0 16 3
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, $this->params);
24
        $this->url = $this->connection->nextUrl;
25
        $this->params = null;
26
        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

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