AbstractAggregate   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 94
ccs 27
cts 27
cp 1
rs 10
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A remove() 0 3 1
A has() 0 3 1
A offsetExists() 0 3 1
A offsetGet() 0 3 1
A __construct() 0 3 1
A get() 0 6 2
A offsetSet() 0 3 1
A getIterator() 0 3 1
A offsetUnset() 0 3 1
1
<?php
2
3
namespace Guillermoandrae\Common;
4
5
use ArrayIterator;
6
7
abstract class AbstractAggregate implements AggregateInterface
8
{
9
    use DumpableTrait;
10
11
    /**
12
     * The items used to build the object.
13
     *
14
     * @var array
15
     */
16
    protected array $items;
17
18
    /**
19
     * Builds the Collection object.
20
     *
21
     * @param array $items  The array of items used to build the aggregate.
22
     */
23 23
    final public function __construct(array $items = [])
24
    {
25 23
        $this->items = $items;
26 23
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 1
    final public function has(mixed $offset): bool
32
    {
33 1
        return $this->offsetExists($offset);
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 4
    final public function get(mixed $offset, mixed $default = null): mixed
40
    {
41 4
        if ($this->offsetExists($offset)) {
42 3
            return $this->items[$offset];
43
        }
44 1
        return $default;
45
    }
46
47
     /**
48
     * {@inheritDoc}
49
     */
50 1
    final public function set(mixed $offset, mixed $value): void
51
    {
52 1
        $this->offsetSet($offset, $value);
53 1
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 1
    public function remove(mixed $offset): void
59
    {
60 1
        $this->offsetUnset($offset);
61 1
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 5
    final public function offsetExists(mixed $offset): bool
67
    {
68 5
        return array_key_exists($offset, $this->items);
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 1
    final public function offsetGet(mixed $offset): mixed
75
    {
76 1
        return $this->items[$offset];
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82 2
    final public function offsetSet(mixed $offset, mixed $value): void
83
    {
84 2
        $this->items[$offset] = $value;
85 2
    }
86
87
    /**
88
     * {@inheritDoc}
89
     */
90 1
    final public function offsetUnset(mixed $offset): void
91
    {
92 1
        unset($this->items[$offset]);
93 1
    }
94
95
    /**
96
     * {@inheritDoc}
97
     */
98 1
    final public function getIterator(): ArrayIterator
99
    {
100 1
        return new ArrayIterator($this->items);
101
    }
102
}
103