Passed
Push — develop ( 1a320a...d6503a )
by Anton
05:47
created

ArrayAccess::offsetExists()   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
/**
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