Completed
Push — master ( 1a3eb9...f4b0a7 )
by John
02:06
created

RepositoryIterator::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Descriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\PhpApi\Descriptions\Description\Respository;
9
10
use KleijnWeb\PhpApi\Descriptions\Description\Repository;
11
12
/**
13
 * @author John Kleijn <[email protected]>
14
 */
15
class RepositoryIterator implements \Iterator
16
{
17
    /**
18
     * @var Repository
19
     */
20
    private $repository;
21
22
    /**
23
     * @var int
24
     */
25
    private $position = 0;
26
27
    /**
28
     * @param Repository $repository
29
     */
30
    public function __construct(Repository $repository)
31
    {
32
        $this->repository = $repository;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function rewind()
39
    {
40
        $this->position = 0;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function current()
47
    {
48
        return $this->repository->get($this->key());
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function key()
55
    {
56
        return $this->repository->getUris()[$this->position];
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function next()
63
    {
64
        ++$this->position;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function valid(): bool
71
    {
72
        return isset($this->repository->getUris()[$this->position]);
73
    }
74
}
75