Completed
Pull Request — master (#1)
by Thibaud
02:49
created

ArrayMetadataIterator::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Alchemy\Resource\Metadata;
4
5
use Assert\Assertion;
6
7
class ArrayMetadataIterator implements MetadataIterator
8
{
9
    /**
10
     * @var Metadata[]
11
     */
12
    private $resources;
13
14
    /**
15
     * @param Metadata[] $metadataResources
16
     */
17 8
    public function __construct(array $metadataResources)
18
    {
19 8
        Assertion::allIsInstanceOf($metadataResources, Metadata::class);
20
21 4
        $this->resources = $metadataResources;
22 4
    }
23
24
    /**
25
     * (PHP 5 &gt;= 5.0.0)<br/>
26
     * Move forward to next element
27
     * @link http://php.net/manual/en/iterator.next.php
28
     * @return void Any returned value is ignored.
29
     */
30 4
    public function next()
31
    {
32 4
        next($this->resources);
33 4
    }
34
35
    /**
36
     * (PHP 5 &gt;= 5.0.0)<br/>
37
     * Return the key of the current element
38
     * @link http://php.net/manual/en/iterator.key.php
39
     * @return mixed scalar on success, or null on failure.
40
     */
41 4
    public function key()
42
    {
43 4
        return key($this->resources);
44
    }
45
46
    /**
47
     * (PHP 5 &gt;= 5.0.0)<br/>
48
     * Checks if current position is valid
49
     * @link http://php.net/manual/en/iterator.valid.php
50
     * @return boolean The return value will be casted to boolean and then evaluated.
51
     * Returns true on success or false on failure.
52
     */
53 4
    public function valid()
54
    {
55 4
        return key($this->resources) !== null;
56
    }
57
58
    /**
59
     * (PHP 5 &gt;= 5.0.0)<br/>
60
     * Rewind the Iterator to the first element
61
     * @link http://php.net/manual/en/iterator.rewind.php
62
     * @return void Any returned value is ignored.
63
     */
64 4
    public function rewind()
65
    {
66 4
        reset($this->resources);
67 4
    }
68
69
    /**
70
     * @return Metadata
71
     */
72 4
    public function current()
73
    {
74 4
        return current($this->resources);
1 ignored issue
show
Comprehensibility Best Practice introduced by
The expression current($this->resources); of type Alchemy\Resource\Metadata\Metadata|false adds false to the return on line 74 which is incompatible with the return type declared by the interface Alchemy\Resource\Metadat...tadataIterator::current of type Alchemy\Resource\Metadata\Metadata. It seems like you forgot to handle an error condition.
Loading history...
75
    }
76
}
77