ArrayAccess   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 52
ccs 9
cts 10
cp 0.9
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 6 2
A offsetGet() 0 3 1
A offsetExists() 0 3 1
A offsetUnset() 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\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
trait ArrayAccess
24
{
25
    use Container;
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(mixed $offset, mixed $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
    }
42
43
    /**
44
     * Offset to retrieve
45
     *
46
     * @param  mixed $offset
47
     *
48
     * @return mixed
49
     */
50 2
    public function offsetGet(mixed $offset): mixed
51
    {
52 2
        return $this->doGetContainer($offset);
53
    }
54
55
    /**
56
     * Whether an offset exists
57
     *
58
     * @param  mixed $offset
59
     *
60
     * @return bool
61
     */
62 2
    public function offsetExists(mixed $offset): bool
63
    {
64 2
        return $this->doContainsContainer($offset);
65
    }
66
67
    /**
68
     * Offset to unset
69
     *
70
     * @param mixed $offset
71
     */
72 2
    public function offsetUnset(mixed $offset): void
73
    {
74 2
        $this->doDeleteContainer($offset);
75
    }
76
}
77