ParameterCollectionTrait::remove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CCT\Component\Collections\Traits;
6
7
trait ParameterCollectionTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $elements;
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 2
    public function set($key, $value): void
18
    {
19 2
        $this->elements[$key] = $value;
20 2
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function get($key, $default = null)
26
    {
27 2
        return $this->has($key)
28 2
            ? $this->elements[$key]
29 2
            : $default
30
        ;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function keys(): array
37
    {
38 1
        return array_keys($this->elements);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function values(): array
45
    {
46 1
        return array_values($this->elements);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 3
    public function remove($key)
53
    {
54 3
        if (false === $this->has($key)) {
55 1
            return null;
56
        }
57
58 3
        $element = $this->elements[$key];
59 3
        unset($this->elements[$key]);
60
61 3
        return $element;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 2
    public function addElements(array $elements): void
68
    {
69 2
        $this->elements = array_replace($this->elements, $elements);
70 2
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 1
    public function clear(): void
76
    {
77 1
        $this->elements = [];
78 1
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 1
    public function replace(array $elements = []): void
84
    {
85 1
        $this->elements = $elements;
86 1
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 5
    public function has($key) : bool
92
    {
93 5
        return isset($this->elements[$key]) || array_key_exists($key, $this->elements);
94
    }
95
}
96