Completed
Push — master ( 2d02b0...698bc6 )
by Thibaud
19:46 queued 17:30
created

ArrayMetadataIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
1
<?php
2
3
/*
4
 * This file is part of alchemy/resource-component.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Resource\Metadata;
13
14
use Assert\Assertion;
15
16
class ArrayMetadataIterator implements MetadataIterator
17
{
18
    /**
19
     * @var Metadata[]
20
     */
21
    private $resources;
22
23
    /**
24
     * @param Metadata[] $metadataResources
25
     */
26 8
    public function __construct(array $metadataResources)
27
    {
28 8
        Assertion::allIsInstanceOf($metadataResources, Metadata::class);
29
30 4
        $this->resources = $metadataResources;
31 4
    }
32
33
    /**
34
     * (PHP 5 &gt;= 5.0.0)<br/>
35
     * Move forward to next element
36
     * @link http://php.net/manual/en/iterator.next.php
37
     * @return void Any returned value is ignored.
38
     */
39 4
    public function next()
40
    {
41 4
        next($this->resources);
42 4
    }
43
44
    /**
45
     * (PHP 5 &gt;= 5.0.0)<br/>
46
     * Return the key of the current element
47
     * @link http://php.net/manual/en/iterator.key.php
48
     * @return mixed scalar on success, or null on failure.
49
     */
50 4
    public function key()
51
    {
52 4
        return key($this->resources);
53
    }
54
55
    /**
56
     * (PHP 5 &gt;= 5.0.0)<br/>
57
     * Checks if current position is valid
58
     * @link http://php.net/manual/en/iterator.valid.php
59
     * @return boolean The return value will be casted to boolean and then evaluated.
60
     * Returns true on success or false on failure.
61
     */
62 4
    public function valid()
63
    {
64 4
        return key($this->resources) !== null;
65
    }
66
67
    /**
68
     * (PHP 5 &gt;= 5.0.0)<br/>
69
     * Rewind the Iterator to the first element
70
     * @link http://php.net/manual/en/iterator.rewind.php
71
     * @return void Any returned value is ignored.
72
     */
73 4
    public function rewind()
74
    {
75 4
        reset($this->resources);
76 4
    }
77
78
    /**
79
     * @return Metadata
80
     */
81 4
    public function current()
82
    {
83 4
        return current($this->resources);
84
    }
85
}
86