Collection::count()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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
        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