Passed
Push — master ( 337d8e...76e5f0 )
by Gabriel
02:33
created

ArrayAccessTrait::offsetGet()   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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
/**
6
 * Class ArrayAccessTrait
7
 * @package Nip\Collections
8
 */
9
trait ArrayAccessTrait
10
{
11
12
    /**
13
     * Determine if the given configuration option exists.
14
     *
15
     * @param  string $key
16
     * @return bool
17
     */
18 2
    public function offsetExists($key)
19
    {
20 2
        return isset($this->items[$key]) || array_key_exists($key, $this->items);
21
    }
22
23
    /**
24
     * Get a configuration option.
25
     *
26
     * @param  string $key
27
     * @return mixed
28
     */
29 4
    public function offsetGet($key)
30
    {
31 4
        return $this->items[$key];
32
    }
33
34
    /**
35
     * @param  string $key
36
     * @param  mixed $value
37
     * @return void
38
     */
39 21
    public function offsetSet($key, $value)
40
    {
41 21
        if (is_null($key)) {
0 ignored issues
show
introduced by
The condition is_null($key) is always false.
Loading history...
42 15
            $this->items[] = $value;
43
        } else {
44 19
            $this->items[$key] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property items does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
        }
46 21
    }
47
48
    /**
49
     * Unset a configuration option.
50
     *
51
     * @inheritdoc
52
     */
53 1
    public function offsetUnset($key)
54
    {
55 1
        unset($this->items[$key]);
56 1
    }
57
}
58