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