Collection   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 13
dl 0
loc 99
c 0
b 0
f 0
ccs 23
cts 23
cp 1
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A last() 0 3 1
A key() 0 3 1
A first() 0 3 1
A getIterator() 0 3 1
A isEmpty() 0 3 1
A all() 0 3 1
A __construct() 0 3 1
A current() 0 3 1
A next() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CCT\Component\Collections;
6
7
class Collection implements CollectionInterface
8
{
9
    /**
10
     * An array containing the entries of this collection.
11
     *
12
     * @var array
13
     */
14
    protected $elements;
15
16
    /**
17
     * Initializes a new ArrayCollection.
18
     *
19
     * @param array $elements
20
     */
21 55
    public function __construct(array $elements = [])
22
    {
23 55
        $this->elements = $elements;
24 55
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function isEmpty(): bool
30
    {
31 1
        return empty($this->elements);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 21
    public function all(): array
38
    {
39 21
        return $this->elements;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 10
    public function count()
46
    {
47 10
        return count($this->elements);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 6
    public function first()
54
    {
55 6
        return reset($this->elements);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 4
    public function last()
62
    {
63 4
        return end($this->elements);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 6
    public function key()
70
    {
71 6
        return key($this->elements);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 9
    public function next()
78
    {
79 9
        return next($this->elements);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 6
    public function current()
86
    {
87 6
        return current($this->elements);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 3
    public function getIterator()
94
    {
95 3
        return new \ArrayIterator($this->elements);
96
    }
97
98
    /**
99
     * Returns a string representation of this object.
100
     *
101
     * @return string
102
     */
103 1
    public function __toString()
104
    {
105 1
        return __CLASS__ . '@' . spl_object_hash($this);
106
    }
107
}
108