BaseCollection   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 3 1
A count() 0 3 1
A offsetUnset() 0 3 1
A offsetExists() 0 3 1
A __construct() 0 3 1
A getIterator() 0 3 1
A offsetSet() 0 6 2
1
<?php
2
/**
3
 * Created by solly [18.10.17 11:05]
4
 */
5
6
namespace insolita\codestat\lib\collection;
7
8
use ArrayAccess;
9
use ArrayIterator;
10
11
class BaseCollection implements ArrayAccess, \IteratorAggregate, \Countable
12
{
13
    protected $items = [];
14
    
15
    public function __construct(array $items = [])
16
    {
17
        $this->items = $items;
18
    }
19
    
20
    public function getIterator()
21
    {
22
        return new ArrayIterator($this->items);
23
    }
24
    
25
    /**
26
     * Count the number of items in the collection.
27
     *
28
     * @return int
29
     */
30
    public function count()
31
    {
32
        return count($this->items);
33
    }
34
    
35
    /**
36
     * Determine if an item exists at an offset.
37
     *
38
     * @param  mixed $key
39
     *
40
     * @return bool
41
     */
42
    public function offsetExists($key)
43
    {
44
        return array_key_exists($key, $this->items);
45
    }
46
    
47
    /**
48
     * Get an item at a given offset.
49
     *
50
     * @param  mixed $key
51
     *
52
     * @return mixed
53
     */
54
    public function offsetGet($key)
55
    {
56
        return $this->items[$key];
57
    }
58
    
59
    /**
60
     * Set the item at a given offset.
61
     *
62
     * @param  mixed $key
63
     * @param  mixed $value
64
     *
65
     * @return void
66
     */
67
    public function offsetSet($key, $value)
68
    {
69
        if (is_null($key)) {
70
            $this->items[] = $value;
71
        } else {
72
            $this->items[$key] = $value;
73
        }
74
    }
75
    
76
    /**
77
     * Unset the item at a given offset.
78
     *
79
     * @param  string $key
80
     *
81
     * @return void
82
     */
83
    public function offsetUnset($key)
84
    {
85
        unset($this->items[$key]);
86
    }
87
    
88
}
89