AbstractIterable   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 76
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A current() 0 4 1
A next() 0 4 1
A valid() 0 6 2
A key() 0 4 1
A rewind() 0 4 1
A count() 0 4 1
1
<?php declare(strict_types=1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 08.04.17 at 09:13
5
 */
6
namespace samsonframework\stringconditiontree;
7
8
use Countable;
9
use Iterator;
10
11
/**
12
 * Class GenericIterable
13
 *
14
 * @author Vitaly Egorov <[email protected]>
15
 */
16
abstract class AbstractIterable implements Iterator, Countable
17
{
18
    /** string Internal collection name for iteration and counting */
19
    protected const COLLECTION_NAME = 'internalCollection';
20
21
    /** @var array Internal internalCollection storage */
22
    private $internalCollection;
23
24
    /**
25
     * GenericIterable constructor.
26
     *
27
     */
28 22
    public function __construct()
29
    {
30 22
        $collectionName = static::COLLECTION_NAME;
31
32
        // Set pointer for internal iterable and countable collection to passed property by its name
33 22
        $this->internalCollection = &$this->$collectionName;
34
35
        // Set empty array
36 22
        $this->internalCollection = [];
37 22
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 5
    public function current()
43
    {
44 5
        return current($this->internalCollection);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 5
    public function next()
51
    {
52 5
        next($this->internalCollection);
53 5
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 5
    public function valid()
59
    {
60 5
        $key = $this->key();
61
62 5
        return ($key !== null && $key !== false);
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 5
    public function key()
69
    {
70 5
        return key($this->internalCollection);
71
    }
72
73
    /**
74
     * Rewind the Iterator to the first element
75
     * @link  http://php.net/manual/en/iterator.rewind.php
76
     * @return void Any returned value is ignored.
77
     * @since 5.0.0
78
     */
79 5
    public function rewind()
80
    {
81 5
        reset($this->internalCollection);
82 5
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 3
    public function count()
88
    {
89 3
        return count($this->internalCollection);
90
    }
91
}
92