Total Complexity | 9 |
Total Lines | 99 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
19 | class Scope |
||
20 | { |
||
21 | /** |
||
22 | * @var self |
||
23 | */ |
||
24 | private $parent; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | private $data = []; |
||
30 | |||
31 | /** |
||
32 | * @var bool |
||
33 | */ |
||
34 | private $left = false; |
||
35 | |||
36 | /** |
||
37 | * @param self|null $parent |
||
38 | */ |
||
39 | 10 | public function __construct(self $parent = null) |
|
40 | { |
||
41 | 10 | $this->parent = $parent; |
|
42 | 10 | } |
|
43 | |||
44 | /** |
||
45 | * Opens a new child scope. |
||
46 | * |
||
47 | * @return self |
||
48 | */ |
||
49 | 7 | public function enter() |
|
50 | { |
||
51 | 7 | return new self($this); |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * Closes current scope and returns parent one. |
||
56 | * |
||
57 | * @return self|null |
||
58 | */ |
||
59 | 5 | public function leave() |
|
60 | { |
||
61 | 5 | $this->left = true; |
|
62 | |||
63 | 5 | return $this->parent; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Stores data into current scope. |
||
68 | * |
||
69 | * @param string $key |
||
70 | * @param mixed $value |
||
71 | * |
||
72 | * @return $this |
||
73 | * |
||
74 | * @throws \LogicException |
||
75 | */ |
||
76 | 7 | public function set($key, $value) |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Tests if a data is visible from current scope. |
||
89 | * |
||
90 | * @param string $key |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | 6 | public function has($key) |
|
101 | } |
||
102 | |||
103 | /** |
||
104 | * Returns data visible from current scope. |
||
105 | * |
||
106 | * @param string $key |
||
107 | * @param mixed $default |
||
108 | * |
||
109 | * @return mixed |
||
110 | */ |
||
111 | 7 | public function get($key, $default = null) |
|
118 | } |
||
119 | } |
||
120 |