Completed
Push — master ( b2620d...cacd0e )
by Gabriel
02:27
created

Collection   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 46.43%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 63
ccs 13
cts 28
cp 0.4643
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A replace() 0 4 1
A add() 0 4 1
A first() 0 4 2
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 3
    public function __construct(array $items = [])
15
    {
16 3
        $this->items = $items;
17 3
    }
18
19
    public function replace(array $items = [])
20
    {
21
        $this->items = $items;
22
    }
23
24 3
    public function add($item)
25
    {
26 3
        $this->items[] = $item;
27 3
    }
28
29 2
    public function first()
30
    {
31 2
        return isset($this->items[0]) ? $this->items[0] : null;
32
    }
33
34
    public function jsonSerialize()
35
    {
36 2
        return array_map(function (JsonSerializable $item) {
37 2
            return $item->jsonSerialize();
38 2
        }, $this->items);
39
    }
40
41 1
    public function count()
42
    {
43 1
        return count($this->items);
44
    }
45
46
    public function current()
47
    {
48
        return current($this->items);
49
    }
50
51
    public function next()
52
    {
53
        return next($this->items);
54
    }
55
56
    public function key()
57
    {
58
        return key($this->items);
59
    }
60
61
    public function valid()
62
    {
63
        $key = key($this->items);
64
        return ($key !== null && $key !== false);
65
    }
66
67
    public function rewind()
68
    {
69
        reset($this->items);
70
    }
71
}
72