ArrayAccessTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 48
ccs 11
cts 11
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 3 2
A offsetSet() 0 3 1
A offsetGet() 0 6 2
A offsetUnset() 0 3 1
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