Completed
Push — master ( 429f57...47a737 )
by René
02:19
created

Collection::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 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
        $item = current($this->collection);
23
24 1
        return $item;
25
    }
26
27
    /**
28
     * Return the key of the current item
29
     *
30
     * @return mixed scalar on success, or null on failure.
31
     */
32 1
    public function key()
33
    {
34 1
        $key = key($this->collection);
35
36 1
        return $key;
37
    }
38
39
    /**
40
     * Move forward to next item
41
     */
42 2
    public function next()
43
    {
44 2
        next($this->collection);
45 2
    }
46
47
    /**
48
     * Rewind the collection to the first item
49
     */
50 2
    public function rewind()
51
    {
52 2
        if (is_array($this->collection) === true) {
53 2
            reset($this->collection);
54
        }
55 2
    }
56
57
    /**
58
     * Checks if current position is valid
59
     *
60
     * @return bool Returns true on success or false on failure.
61
     */
62 1
    public function valid(): bool
63
    {
64 1
        $key = key($this->collection);
65
66 1
        if ($key !== null && $key !== false) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return $key !== null && $key !== false;.
Loading history...
67 1
            return true;
68
        } else {
69 1
            return false;
70
        }
71
    }
72
73
    /**
74
     * Count elements of items in collection
75
     *
76
     * @return int Count
77
     */
78 1
    public function count(): int
79
    {
80 1
        $count = count($this->collection);
81
82 1
        return $count;
83
    }
84
}
85