ArrayAccessTrait::offsetUnset()   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 0
Metric Value
cc 1
eloc 1
c 0
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
namespace ByTIC\DataObjects\Behaviors\ArrayAccess;
4
5
/**
6
 * Trait ArrayAccessTrait
7
 * @package ByTIC\DataObjects\Behaviors\ArrayAccess
8
 */
9
trait ArrayAccessTrait
10
{
11
    /**
12
     * Determine if the given attribute exists.
13
     *
14
     * @param mixed $offset
15
     * @return bool
16
     */
17 4
    public function offsetExists($offset): bool
18
    {
19 4
        return isset($this->{$offset}) && !is_null($this->{$offset});
20
    }
21
22
    /**
23
     * Get the value for a given offset.
24
     *
25
     * @param mixed $offset
26
     * @return mixed
27
     */
28 2
    public function offsetGet($offset)
29
    {
30 2
        if (!$this->offsetExists($offset)) {
31 1
            return null;
32
        }
33 2
        return $this->{$offset};
34
    }
35
36
    /**
37
     * Set the value for a given offset.
38
     *
39
     * @param mixed $offset
40
     * @param mixed $value
41
     * @return void
42
     */
43 2
    public function offsetSet($offset, $value)
44
    {
45 2
        $this->{$offset} = $value;
46 2
    }
47
48
    /**
49
     * Unset the value for a given offset.
50
     *
51
     * @param mixed $offset
52
     * @return void
53
     */
54 1
    public function offsetUnset($offset)
55
    {
56 1
        unset($this->{$offset});
57 1
    }
58
}
59