Passed
Push — master ( 4d2a94...142804 )
by Sebastian
03:29
created

PropertyAccessTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 5
dl 0
loc 86
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 3 1
A __unset() 0 3 1
A __set() 0 3 1
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\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
    abstract public function set($key, $value);
41
42
    /**
43
     * Express Requirements by Abstract Methods.
44
     *
45
     * @param string $key
46
     */
47
    abstract public function delete($key): bool;
48
49
    /**
50
     * Set
51
     * http://php.net/manual/en/language.oop5.overloading.php.
52
     *
53
     * @param string $key
54
     * @param mixed  $value
55
     *
56
     * @ignore
57
     */
58 18
    public function __set(string $key, $value)
59
    {
60 18
        $this->set($key, $value);
61 18
    }
62
63
    /**
64
     * Get
65
     * http://php.net/manual/en/language.oop5.overloading.php.
66
     *
67
     * @param string $key
68
     *
69
     * @return object|bool Element stored in container or false
70
     *
71
     * @ignore
72
     */
73 12
    public function __get(string $key)
74
    {
75 12
        return $this->get($key);
76
    }
77
78
    /**
79
     * Remove
80
     * http://php.net/manual/en/language.oop5.overloading.php.
81
     *
82
     * @param string $key
83
     *
84
     * @ignore
85
     */
86 6
    public function __unset(string $key)
87
    {
88 6
        $this->delete($key);
89 6
    }
90
91
    /**
92
     * Check
93
     * http://php.net/manual/en/language.oop5.overloading.php.
94
     *
95
     * @param string $key
96
     *
97
     * @return bool
98
     *
99
     * @ignore
100
     */
101 12
    public function __isset(string $key): bool
102
    {
103 12
        return $this->has($key);
104
    }
105
}
106