ResourceCollection::getData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
namespace Aeq\Hal\Explorer;
3
4
use Aeq\Hal\Explorer;
5
use Aeq\Hal\Explorer\Resource as HalResource;
6
7
class ResourceCollection implements \Iterator, ResourceInterface
8
{
9
    /**
10
     * @var ResourceInterface[]
11
     */
12
    private $resources = [];
13
14
    /**
15
     * @var Explorer
16
     */
17
    private $explorer;
18
19
    /**
20
     * @param Explorer $explorer
21
     */
22 1
    public function __construct(Explorer $explorer)
23
    {
24 1
        $this->explorer = $explorer;
25 1
    }
26
27
    /**
28
     * @param ResourceInterface $resource
29
     */
30 1
    public function addResource(ResourceInterface $resource)
31
    {
32 1
        $this->resources[] = $resource;
33 1
    }
34
35
    /**
36
     * @return HalResource
37
     */
38 1
    public function current()
39
    {
40 1
        return current($this->resources);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression current($this->resources); of type Aeq\Hal\Explorer\ResourceInterface|false adds false to the return on line 40 which is incompatible with the return type documented by Aeq\Hal\Explorer\ResourceCollection::current of type Aeq\Hal\Explorer\Resource. It seems like you forgot to handle an error condition.
Loading history...
41
    }
42
43
    /**
44
     * @return void
45
     */
46 1
    public function next()
47
    {
48 1
        next($this->resources);
49 1
    }
50
51
    /**
52
     * @return mixed
53
     */
54 1
    public function key()
55
    {
56 1
        return key($this->resources);
57
    }
58
59
    /**
60
     * @return bool
61
     */
62 1
    public function valid()
63
    {
64 1
        return key($this->resources) !== null;
65
    }
66
67
    /**
68
     * @return void
69
     */
70 1
    public function rewind()
71
    {
72 1
        reset($this->resources);
73 1
    }
74
75
    /**
76
     * @return array
77
     */
78 4
    public function getData()
79
    {
80 4
        $data = [];
81 4
        foreach ($this->resources as $item) {
82 2
            $data[] = $item->getData();
83 4
        }
84 4
        return $data;
85
    }
86
}
87