Completed
Push — master ( fa2f9e...da6516 )
by Gabriel
02:23
created

Collection   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 44%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 58
ccs 11
cts 25
cp 0.44
rs 10
c 0
b 0
f 0

10 Methods

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