ArrayAccess::offsetExists()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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