Completed
Push — master ( 91f80b...b28fcf )
by Denis
01:47
created

CollectionIterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 78
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A current() 0 4 1
A next() 0 4 1
A valid() 0 6 2
A key() 0 4 1
A rewind() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dp
5
 * Date: 31.07.17
6
 * Time: 16:37
7
 */
8
9
namespace Lan\Ebs\Sdk\Classes;
10
11
use ArrayIterator;
12
13
class CollectionIterator extends ArrayIterator
14
{
15
    /**
16
     * @var Collection
17
     */
18
    private $collection;
19
20
    private $data = [];
21
22
    /**
23
     * CollectionIterator constructor.
24
     *
25
     * @param Collection $collection
26
     */
27 2
    public function __construct(Collection $collection)
28
    {
29 2
        $this->collection = $collection;
30 2
    }
31
32
    /**
33
     * Return the current element
34
     *
35
     * @link   http://php.net/manual/en/iterator.current.php
36
     * @return Model
37
     */
38 2
    public function current()
39
    {
40 2
        return $this->collection->createModel(current($this->data));
41
    }
42
43
    /**
44
     * Move forward to next element
45
     *
46
     * @link   http://php.net/manual/en/iterator.next.php
47
     * @return Model
48
     */
49 2
    public function next()
50
    {
51 2
        return next($this->data);
52
    }
53
54
    /**
55
     * Checks if current position is valid
56
     *
57
     * @link   http://php.net/manual/en/iterator.valid.php
58
     * @return boolean
59
     */
60 2
    public function valid()
61
    {
62 2
        $key = $this->key();
63
64 2
        return ($key !== null && $key !== false);
65
    }
66
67
    /**
68
     * Return the key of the current element
69
     *
70
     * @link   http://php.net/manual/en/iterator.key.php
71
     * @return integer
72
     */
73 2
    public function key()
74
    {
75 2
        return key($this->data);
76
    }
77
78
    /**
79
     * Rewind the Iterator to the first element
80
     *
81
     * @link   http://php.net/manual/en/iterator.rewind.php
82
     * @return void
83
     */
84 2
    public function rewind()
85
    {
86 2
        $this->data = $this->collection->load()->getData();
87
88 2
        reset($this->data);
89
    }
90
}