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

PropertyAccessTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A __unset() 0 3 1
A __get() 0 7 2
A __isset() 0 3 1
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
 * Magic Access Trait
16
 * Provide to Session the possibility to retrive values using properties.
17
 *
18
 * @property mixed $data Session Data
19
 */
20
trait PropertyAccessTrait
21
{
22
    /**
23
     * Magic metod
24
     * http://php.net/manual/en/language.oop5.overloading.php.
25
     *
26
     * @param string $offset
27
     * @param mixed  $value
28
     *
29
     * @return void
30
     */
31 22
    public function __set(string $offset, $value)
32
    {
33 22
        $this->data[$offset] = $value;
34 22
    }
35
36
    /**
37
     * Magic metod
38
     * http://php.net/manual/en/language.oop5.overloading.php.
39
     *
40
     * @param string $offset
41
     *
42
     * @return mixed
43
     */
44 23
    public function __get(string $offset)
45
    {
46 23
        if (isset($this->data[$offset])) {
47 22
            return $this->data[$offset];
48
        }
49
50 1
        return false;
51
    }
52
53
    /**
54
     * Magic metod
55
     * http://php.net/manual/en/language.oop5.overloading.php.
56
     *
57
     * @param string $offset
58
     */
59 3
    public function __unset(string $offset)
60
    {
61 3
        unset($this->data[$offset]);
62 3
    }
63
64
    /**
65
     * Magic metod
66
     * http://php.net/manual/en/language.oop5.overloading.php.
67
     *
68
     * @param string $offset
69
     */
70 20
    public function __isset(string $offset)
71
    {
72 20
        return isset($this->data[$offset]);
73
    }
74
}
75