Completed
Push — b0.27.0 ( c529b3...34cc26 )
by Sebastian
05:07
created

ArrayAccessTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A offsetExists() 0 3 1
A offsetUnset() 0 3 1
A offsetGet() 0 7 2
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Session;
13
14
/**
15
 * Array Access Trait
16
 * Provide to Session the possibility to retrive values using array notation.
17
 *
18
 * @property mixed $data Session Data
19
 */
20
trait ArrayAccessTrait
21
{
22
    /**
23
     * Check.
24
     *
25
     * @param string $offset
26
     *
27
     * @return bool
28
     */
29 2
    public function offsetExists($offset)
30
    {
31 2
        return isset($this->data[$offset]);
32
    }
33
34
    /**
35
     * Get.
36
     *
37
     * @param string $offset
38
     *
39
     * @return mixed
40
     */
41 16
    public function offsetGet($offset)
42
    {
43 16
        if (isset($this->data[$offset])) {
44 14
            return $this->data[$offset];
45
        }
46
47 6
        return false;
48
    }
49
50
    /**
51
     * Store.
52
     *
53
     * @param string $offset
54
     * @param mixed  $value
55
     *
56
     * @return void
57
     */
58 14
    public function offsetSet($offset, $value)
59
    {
60 14
        $this->data[$offset] = $value;
61 14
    }
62
63
    /**
64
     * Delete.
65
     *
66
     * @param string $offset
67
     *
68
     * @return void
69
     */
70 2
    public function offsetUnset($offset)
71
    {
72 2
        unset($this->data[$offset]);
73 2
    }
74
}
75