Collection   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
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 65
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 6 2
A valid() 0 6 2
A count() 0 4 1
1
<?php
2
3
namespace Zortje\Rules\Common;
4
5
/**
6
 * Class Collection
7
 *
8
 * @package Zortje\Rules\Common
9
 */
10
class Collection implements \Iterator, \Countable
11
{
12
13
    protected $collection = [];
14
15
    /**
16
     * Return the current item
17
     *
18
     * @return false|mixed Item
19
     */
20 1
    public function current()
21
    {
22 1
        return current($this->collection);
23
    }
24
25
    /**
26
     * Return the key of the current item
27
     *
28
     * @return mixed scalar on success, or null on failure.
29
     */
30 1
    public function key()
31
    {
32 1
        return key($this->collection);
33
    }
34
35
    /**
36
     * Move forward to next item
37
     */
38 2
    public function next()
39
    {
40 2
        next($this->collection);
41 2
    }
42
43
    /**
44
     * Rewind the collection to the first item
45
     */
46 2
    public function rewind()
47
    {
48 2
        if (is_array($this->collection) === true) {
49 2
            reset($this->collection);
50
        }
51 2
    }
52
53
    /**
54
     * Checks if current position is valid
55
     *
56
     * @return bool Returns true on success or false on failure.
57
     */
58 1
    public function valid(): bool
59
    {
60 1
        $key = key($this->collection);
61
62 1
        return $key !== null && $key !== false;
63
    }
64
65
    /**
66
     * Count elements of items in collection
67
     *
68
     * @return int Count
69
     */
70 1
    public function count(): int
71
    {
72 1
        return count($this->collection);
73
    }
74
}
75