PropertyAccessTrait::__get()   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
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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\Container;
13
14
/**
15
 * Magic Access Trait
16
 * Provide to DIContainer the possibility to retrive values using properties.
17
 */
18
trait PropertyAccessTrait
19
{
20
    /**
21
     * Express Requirements by Abstract Methods.
22
     *
23
     * @param string $key
24
     */
25
    abstract public function has($key);
26
27
    /**
28
     * Express Requirements by Abstract Methods.
29
     *
30
     * @param string $key
31
     */
32
    abstract public function get($key);
33
34
    /**
35
     * Express Requirements by Abstract Methods.
36
     *
37
     * @param string $key
38
     * @param mixed  $value
39
     *
40
     * @return void
41
     */
42
    abstract public function set($key, $value);
43
44
    /**
45
     * Express Requirements by Abstract Methods.
46
     *
47
     * @param string $key
48
     */
49
    abstract public function delete($key): bool;
50
51
    /**
52
     * Set
53
     * http://php.net/manual/en/language.oop5.overloading.php.
54
     *
55
     * @param string $key
56
     * @param mixed  $value
57
     *
58
     * @return void
59
     *
60
     * @ignore
61
     */
62 18
    public function __set(string $key, $value)
63
    {
64 18
        $this->set($key, $value);
65 18
    }
66
67
    /**
68
     * Get
69
     * http://php.net/manual/en/language.oop5.overloading.php.
70
     *
71
     * @param string $key
72
     *
73
     * @return object|bool Element stored in container or false
74
     *
75
     * @ignore
76
     */
77 12
    public function __get(string $key)
78
    {
79 12
        return $this->get($key);
80
    }
81
82
    /**
83
     * Remove
84
     * http://php.net/manual/en/language.oop5.overloading.php.
85
     *
86
     * @param string $key
87
     *
88
     * @ignore
89
     */
90 6
    public function __unset(string $key)
91
    {
92 6
        $this->delete($key);
93 6
    }
94
95
    /**
96
     * Check
97
     * http://php.net/manual/en/language.oop5.overloading.php.
98
     *
99
     * @param string $key
100
     *
101
     * @return bool
102
     *
103
     * @ignore
104
     */
105 12
    public function __isset(string $key): bool
106
    {
107 12
        return $this->has($key);
108
    }
109
}
110