Completed
Push — master ( c3c281...ab94e9 )
by Gabriel
03:37
created

Collection   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 53
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 4 1
A jsonSerialize() 0 6 1
A count() 0 4 1
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 5 2
A rewind() 0 4 1
1
<?php
2
3
namespace Waredesk;
4
5
use Iterator;
6
use Countable;
7
use JsonSerializable;
8
9
abstract class Collection implements Iterator, Countable, JsonSerializable
10
{
11
    protected $items;
12
    protected $key;
13
14
    public function __construct(array $items = [])
15
    {
16
        $this->items = $items;
17
    }
18
19
    public function add($item)
20
    {
21
        $this->items[] = $item;
22
    }
23
24
    public function jsonSerialize()
25
    {
26
        return array_map(function (JsonSerializable $item) {
27
            return $item->jsonSerialize();
28
        }, $this->items);
29
    }
30
31
    public function count()
32
    {
33
        return count($this->items);
34
    }
35
36
    public function current()
37
    {
38
        return current($this->items);
39
    }
40
41
    public function next()
42
    {
43
        return next($this->items);
44
    }
45
46
    public function key()
47
    {
48
        return key($this->items);
49
    }
50
51
    public function valid()
52
    {
53
        $key = key($this->items);
54
        return ($key !== null && $key !== false);
55
    }
56
57
    public function rewind()
58
    {
59
        reset($this->items);
60
    }
61
}
62