Completed
Pull Request — master (#466)
by Anton
14:29 queued 12:20
created

ArrayAccess::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Common\Container;
12
13
/**
14
 * Container implements ArrayAccess
15
 *
16
 * @package  Bluz\Common
17
 * @author   Anton Shevchuk
18
 * @see      ArrayAccess
19
 *
20
 * @method   void  doSetContainer($key, $value)
21
 * @method   mixed doGetContainer($key)
22
 * @method   bool  doContainsContainer($key)
23
 * @method   void  doDeleteContainer($key)
24
 */
25
trait ArrayAccess
26
{
27
    /**
28
     * Offset to set
29
     *
30
     * @param  mixed $offset
31
     * @param  mixed $value
32
     *
33
     * @throws \InvalidArgumentException
34
     */
35 2
    public function offsetSet($offset, $value): void
36
    {
37 2
        if (null === $offset) {
38
            throw new \InvalidArgumentException('Class `Common\Container\ArrayAccess` support only associative arrays');
39
        }
40 2
        $this->doSetContainer($offset, $value);
41 2
    }
42
43
    /**
44
     * Offset to retrieve
45
     *
46
     * @param  mixed $offset
47
     *
48
     * @return mixed
49
     */
50 5
    public function offsetGet($offset)
51
    {
52 5
        return $this->doGetContainer($offset);
53
    }
54
55
    /**
56
     * Whether a offset exists
57
     *
58
     * @param  mixed $offset
59
     *
60
     * @return bool
61
     */
62 5
    public function offsetExists($offset): bool
63
    {
64 5
        return $this->doContainsContainer($offset);
65
    }
66
67
    /**
68
     * Offset to unset
69
     *
70
     * @param mixed $offset
71
     */
72 2
    public function offsetUnset($offset): void
73
    {
74 2
        $this->doDeleteContainer($offset);
75 2
    }
76
}
77