Completed
Pull Request — master (#466)
by Anton
12:30 queued 10:37
created

ArrayAccess   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 50
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 6 2
A offsetExists() 0 3 1
A offsetGet() 0 3 1
A offsetUnset() 0 3 1
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