Completed
Branch full-rewrite (4754d3)
by Thibaud
03:13
created

AbstractIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 67
wmc 6
lcom 1
cbo 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
buildIterator() 0 1 ?
A getIterator() 0 8 2
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
1
<?php
2
3
namespace Alchemy\Zippy\Package\Iterator;
4
5
use Alchemy\Zippy\Package\PackagedResourceIterator;
6
7
abstract class AbstractIterator implements PackagedResourceIterator
8
{
9
10
   /**
11
     * @return \Iterator
12
     */
13
    abstract protected function buildIterator();
14
15
    /**
16
     * @return \Iterator
17
     */
18
    public function getIterator()
19
    {
20
        if (! isset($this->iterator)) {
21
            $this->iterator = $this->buildIterator();
0 ignored issues
show
Bug introduced by
The property iterator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        }
23
24
        return $this->iterator;
25
    }
26
27
    /**
28
     * (PHP 5 &gt;= 5.0.0)<br/>
29
     * Move forward to next element
30
     * @link http://php.net/manual/en/iterator.next.php
31
     * @return void Any returned value is ignored.
32
     */
33
    public function next()
34
    {
35
        $this->getIterator()->next();
36
    }
37
38
    /**
39
     * (PHP 5 &gt;= 5.0.0)<br/>
40
     * Return the key of the current element
41
     * @link http://php.net/manual/en/iterator.key.php
42
     * @return mixed scalar on success, or null on failure.
43
     */
44
    public function key()
45
    {
46
        return $this->getIterator()->key();
47
    }
48
49
    /**
50
     * (PHP 5 &gt;= 5.0.0)<br/>
51
     * Checks if current position is valid
52
     * @link http://php.net/manual/en/iterator.valid.php
53
     * @return boolean The return value will be casted to boolean and then evaluated.
54
     * Returns true on success or false on failure.
55
     */
56
    public function valid()
57
    {
58
        return $this->getIterator()->valid();
59
    }
60
61
    /**
62
     * (PHP 5 &gt;= 5.0.0)<br/>
63
     * Rewind the Iterator to the first element
64
     * @link http://php.net/manual/en/iterator.rewind.php
65
     * @return void Any returned value is ignored.
66
     */
67
    public function rewind()
68
    {
69
        $this->getIterator()->rewind();
70
    }
71
72
73
}
74