@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php namespace Knot\Dict; |
2 | 2 | |
3 | -use ArrayAccess; |
|
4 | 3 | use Countable; |
5 | 4 | use Illuminate\Contracts\Support\Arrayable; |
6 | 5 | use IteratorAggregate; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function __construct(array &$data, AbstractDictBody $parent = null, $path = '') |
50 | 50 | { |
51 | - $this->data =& $data; |
|
51 | + $this->data = & $data; |
|
52 | 52 | $this->path = $path; |
53 | 53 | $this->parentArray = $parent; |
54 | 54 | } |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function &__get($key) |
74 | 74 | { |
75 | - if ( array_key_exists($key, $this->data) ) |
|
75 | + if (array_key_exists($key, $this->data)) |
|
76 | 76 | { |
77 | - $target =& $this->data[$key]; |
|
77 | + $target = & $this->data[$key]; |
|
78 | 78 | } |
79 | 79 | else |
80 | 80 | { |
81 | 81 | throw new WrongArrayPathException($key); |
82 | 82 | } |
83 | 83 | |
84 | - if ( is_array($target) ) |
|
84 | + if (is_array($target)) |
|
85 | 85 | { |
86 | 86 | $r = new ChildDict($target, $this->childParent(), $this->path($key)); |
87 | 87 | |
@@ -101,18 +101,18 @@ discard block |
||
101 | 101 | * @return mixed |
102 | 102 | * @throws \Exception |
103 | 103 | */ |
104 | - public function call($methodPath, array $arguments = [ ]) |
|
104 | + public function call($methodPath, array $arguments = []) |
|
105 | 105 | { |
106 | 106 | $function = $this->get($methodPath, false); |
107 | 107 | |
108 | - if ( ! $function || ! is_callable($function) ) |
|
108 | + if ( ! $function || ! is_callable($function)) |
|
109 | 109 | { |
110 | 110 | throw new WrongFunctionException("Wrong function or not callable key!"); |
111 | 111 | } |
112 | 112 | |
113 | 113 | try |
114 | 114 | { |
115 | - $arguments = array_merge([ &$this->data ], $arguments); |
|
115 | + $arguments = array_merge([&$this->data], $arguments); |
|
116 | 116 | |
117 | 117 | return call_user_func_array($function, $arguments); |
118 | 118 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @return $this|mixed |
133 | 133 | * @throws \Exception|WrongFunctionException |
134 | 134 | */ |
135 | - public function __call($method, $arguments = [ ]) |
|
135 | + public function __call($method, $arguments = []) |
|
136 | 136 | { |
137 | 137 | try |
138 | 138 | { |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __isset($key) |
154 | 154 | { |
155 | - return isset( $this->data[$key] ); |
|
155 | + return isset($this->data[$key]); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function __unset($key) |
163 | 163 | { |
164 | - unset( $this->data[$key] ); |
|
164 | + unset($this->data[$key]); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function keyExists($key) |
189 | 189 | { |
190 | - return isset( $this->data[$key] ); |
|
190 | + return isset($this->data[$key]); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 |
@@ -75,8 +75,7 @@ discard block |
||
75 | 75 | if ( array_key_exists($key, $this->data) ) |
76 | 76 | { |
77 | 77 | $target =& $this->data[$key]; |
78 | - } |
|
79 | - else |
|
78 | + } else |
|
80 | 79 | { |
81 | 80 | throw new WrongArrayPathException($key); |
82 | 81 | } |
@@ -115,8 +114,7 @@ discard block |
||
115 | 114 | $arguments = array_merge([ &$this->data ], $arguments); |
116 | 115 | |
117 | 116 | return call_user_func_array($function, $arguments); |
118 | - } |
|
119 | - catch (\Exception $e) |
|
117 | + } catch (\Exception $e) |
|
120 | 118 | { |
121 | 119 | throw new FunctionExecuteException($methodPath); |
122 | 120 | } |
@@ -137,8 +135,7 @@ discard block |
||
137 | 135 | try |
138 | 136 | { |
139 | 137 | return $this->getHelperManager()->execute($method, $arguments, $this); |
140 | - } |
|
141 | - catch (\Exception $e) |
|
138 | + } catch (\Exception $e) |
|
142 | 139 | { |
143 | 140 | throw $e; |
144 | 141 | } |
@@ -15,6 +15,9 @@ discard block |
||
15 | 15 | protected $path = ''; |
16 | 16 | |
17 | 17 | |
18 | + /** |
|
19 | + * @return null|AbstractDictBody |
|
20 | + */ |
|
18 | 21 | abstract public function childParent(); |
19 | 22 | |
20 | 23 | |
@@ -74,7 +77,7 @@ discard block |
||
74 | 77 | /** |
75 | 78 | * @param $path |
76 | 79 | * |
77 | - * @return array|ChildDict|Mixed |
|
80 | + * @return callable |
|
78 | 81 | * @throws WrongArrayPathException |
79 | 82 | */ |
80 | 83 | public function get($path) |
@@ -184,7 +187,7 @@ discard block |
||
184 | 187 | |
185 | 188 | |
186 | 189 | /** |
187 | - * @param $rawPath |
|
190 | + * @param null|string $rawPath |
|
188 | 191 | * |
189 | 192 | * @return $this |
190 | 193 | */ |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function path($add = null) |
27 | 27 | { |
28 | - return $add ? $this->path != null ? $this->path . self::$ARRAY_PATH_DELIMITER . $add : $add : $this->path; |
|
28 | + return $add ? $this->path != null ? $this->path.self::$ARRAY_PATH_DELIMITER.$add : $add : $this->path; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | |
@@ -81,20 +81,20 @@ discard block |
||
81 | 81 | { |
82 | 82 | $arguments = func_get_args(); |
83 | 83 | |
84 | - if ( isset( $arguments[1] ) ) |
|
84 | + if (isset($arguments[1])) |
|
85 | 85 | { |
86 | 86 | $default_return = $arguments[1]; |
87 | 87 | } |
88 | 88 | |
89 | - $target_data =& $this->data; |
|
89 | + $target_data = & $this->data; |
|
90 | 90 | |
91 | 91 | foreach (static::pathParser($path) as $way) |
92 | 92 | { |
93 | 93 | |
94 | - if ( ! isset( $target_data[$way] ) ) |
|
94 | + if ( ! isset($target_data[$way])) |
|
95 | 95 | { |
96 | 96 | |
97 | - if ( isset( $default_return ) ) |
|
97 | + if (isset($default_return)) |
|
98 | 98 | { |
99 | 99 | $r = $this->set($path, $default_return); |
100 | 100 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $target_data = &$target_data[$way]; |
108 | 108 | } |
109 | 109 | |
110 | - if ( is_array($target_data) ) |
|
110 | + if (is_array($target_data)) |
|
111 | 111 | { |
112 | 112 | return new ChildDict($target_data, $this->childParent(), $path); |
113 | 113 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | $arguments = func_get_args(); |
130 | 130 | |
131 | - if ( isset( $arguments[1] ) ) |
|
131 | + if (isset($arguments[1])) |
|
132 | 132 | { |
133 | 133 | $value = $arguments[1]; |
134 | 134 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | } |
140 | 140 | catch (WrongArrayPathException $e) |
141 | 141 | { |
142 | - if ( isset( $value ) ) |
|
142 | + if (isset($value)) |
|
143 | 143 | { |
144 | - return $this->value($value, [ $path ]); |
|
144 | + return $this->value($value, [$path]); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | throw $e; |
@@ -157,24 +157,24 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function set($rawPath, $value) |
159 | 159 | { |
160 | - $target_data =& $this->data; |
|
160 | + $target_data = & $this->data; |
|
161 | 161 | |
162 | 162 | foreach (static::pathParser($rawPath) as $path) |
163 | 163 | { |
164 | 164 | // If there is no way to go or this is not an array! |
165 | - if ( ! isset( $target_data[$path] ) || ! is_array($target_data[$path]) ) |
|
165 | + if ( ! isset($target_data[$path]) || ! is_array($target_data[$path])) |
|
166 | 166 | { |
167 | - $target_data[$path] = [ ]; |
|
167 | + $target_data[$path] = []; |
|
168 | 168 | } |
169 | 169 | |
170 | - $target_data =& $target_data[$path]; |
|
170 | + $target_data = & $target_data[$path]; |
|
171 | 171 | } |
172 | 172 | |
173 | - $value = $this->value($value, [ $rawPath ]); |
|
173 | + $value = $this->value($value, [$rawPath]); |
|
174 | 174 | |
175 | 175 | $target_data = $value; |
176 | 176 | |
177 | - if ( is_array($target_data) ) |
|
177 | + if (is_array($target_data)) |
|
178 | 178 | { |
179 | 179 | return new ChildDict($target_data, $this->childParent(), $this->path()); |
180 | 180 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function del($rawPath) |
192 | 192 | { |
193 | - $target_data =& $this->data; |
|
193 | + $target_data = & $this->data; |
|
194 | 194 | |
195 | 195 | $paths = static::pathParser($rawPath); |
196 | 196 | |
@@ -199,24 +199,24 @@ discard block |
||
199 | 199 | foreach ($paths as $path) |
200 | 200 | { |
201 | 201 | // If there is no way to go or this is not an array! |
202 | - if ( ! isset( $target_data[$path] ) || ! is_array($target_data[$path]) ) |
|
202 | + if ( ! isset($target_data[$path]) || ! is_array($target_data[$path])) |
|
203 | 203 | { |
204 | 204 | return $this; |
205 | 205 | } |
206 | 206 | |
207 | - $target_data =& $target_data[$path]; |
|
207 | + $target_data = & $target_data[$path]; |
|
208 | 208 | } |
209 | 209 | |
210 | - if ( isset( $target_data[$target_key] ) ) |
|
210 | + if (isset($target_data[$target_key])) |
|
211 | 211 | { |
212 | - unset( $target_data[$target_key] ); |
|
212 | + unset($target_data[$target_key]); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $this; |
216 | 216 | } |
217 | 217 | |
218 | 218 | |
219 | - protected function value($value, array $arguments = [ ]) |
|
219 | + protected function value($value, array $arguments = []) |
|
220 | 220 | { |
221 | 221 | return $value instanceof \Closure ? call_user_func_array($value, $arguments) : $value; |
222 | 222 | } |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | $this->get($path); |
64 | 64 | |
65 | 65 | return true; |
66 | - } |
|
67 | - catch (WrongArrayPathException $e) |
|
66 | + } catch (WrongArrayPathException $e) |
|
68 | 67 | { |
69 | 68 | return false; |
70 | 69 | } |
@@ -136,8 +135,7 @@ discard block |
||
136 | 135 | try |
137 | 136 | { |
138 | 137 | return $this->get($path); |
139 | - } |
|
140 | - catch (WrongArrayPathException $e) |
|
138 | + } catch (WrongArrayPathException $e) |
|
141 | 139 | { |
142 | 140 | if ( isset( $value ) ) |
143 | 141 | { |
@@ -4,6 +4,6 @@ |
||
4 | 4 | |
5 | 5 | public function __toString() |
6 | 6 | { |
7 | - return __CLASS__ . ":[" . $this->code . "]: Wrong Path. Path: " . $this->message . '\n'; |
|
7 | + return __CLASS__.":[".$this->code."]: Wrong Path. Path: ".$this->message.'\n'; |
|
8 | 8 | } |
9 | 9 | } |
10 | 10 | \ No newline at end of file |
@@ -6,6 +6,6 @@ |
||
6 | 6 | |
7 | 7 | public function __toString() |
8 | 8 | { |
9 | - return __CLASS__ . ":[" . $this->code . "]: Function execute error. Function: " . $this->message . '\n'; |
|
9 | + return __CLASS__.":[".$this->code."]: Function execute error. Function: ".$this->message.'\n'; |
|
10 | 10 | } |
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | public function __construct() |
83 | 83 | { |
84 | - if ( class_exists("__") ) |
|
84 | + if (class_exists("__")) |
|
85 | 85 | { |
86 | 86 | $this->ready = true; |
87 | 87 | } |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | public function addRoutes(HelperManager $helperManager) |
98 | 98 | { |
99 | 99 | // If underscore is not exists, don't add any routes to helper. |
100 | - if ( $this->ready === true ) |
|
100 | + if ($this->ready === true) |
|
101 | 101 | { |
102 | 102 | foreach ($this->functions as $functionName) |
103 | 103 | { |
104 | - $helperManager->addRoute($functionName, [ __CLASS__, "execute" ]); |
|
104 | + $helperManager->addRoute($functionName, [__CLASS__, "execute"]); |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $data = $knot->toArray(); |
113 | 113 | |
114 | 114 | $underscoreObject = \__($data); |
115 | - $targetFunction = [ $underscoreObject, $functionName ]; |
|
115 | + $targetFunction = [$underscoreObject, $functionName]; |
|
116 | 116 | |
117 | 117 | return call_user_func_array($targetFunction, $arguments); |
118 | 118 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | foreach ($this->functions as $functionName) |
59 | 59 | { |
60 | 60 | $route = $this->convertPHPFunctionToRoute($functionName); |
61 | - $helperManager->addRoute($route, [ __CLASS__, "execute" ]); |
|
61 | + $helperManager->addRoute($route, [__CLASS__, "execute"]); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public static function execute(AbstractDictBody $knot, $arguments, $methodName) |
67 | 67 | { |
68 | 68 | $methodName = self::convertRouteToPHPFunction($methodName); |
69 | - $data =& $knot->toArray(); |
|
69 | + $data = & $knot->toArray(); |
|
70 | 70 | |
71 | 71 | array_unshift($arguments, $data); |
72 | 72 | $data = call_user_func_array($methodName, $arguments); |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Created by PhpStorm. |
|
4 | - * User: kalaomer |
|
5 | - * Date: 31.05.2015 |
|
6 | - * Time: 01:16 |
|
7 | - */ |
|
3 | + * Created by PhpStorm. |
|
4 | + * User: kalaomer |
|
5 | + * Date: 31.05.2015 |
|
6 | + * Time: 01:16 |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | namespace Knot\Dict\Helpers; |
10 | 10 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | { |
15 | 15 | $route = ltrim($phpFunctionName, "array_"); |
16 | 16 | |
17 | - return preg_replace_callback('/\_([a-z])/', function ($matches) |
|
17 | + return preg_replace_callback('/\_([a-z])/', function($matches) |
|
18 | 18 | { |
19 | 19 | return strtoupper($matches[1]); |
20 | 20 | }, $route); |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | |
24 | 24 | protected static function convertRouteToPHPFunction($route) |
25 | 25 | { |
26 | - $right_side = preg_replace_callback('/([A-Z])/', function ($matches) |
|
26 | + $right_side = preg_replace_callback('/([A-Z])/', function($matches) |
|
27 | 27 | { |
28 | - return '_' . strtolower($matches[1]); |
|
28 | + return '_'.strtolower($matches[1]); |
|
29 | 29 | }, $route); |
30 | 30 | |
31 | - return 'array_' . $right_side; |
|
31 | + return 'array_'.$right_side; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | foreach ($this->functions as $functionName) |
37 | 37 | { |
38 | 38 | $route = $this->convertPHPFunctionToRoute($functionName); |
39 | - $helperManager->addRoute($route, [ __CLASS__, "execute" ]); |
|
39 | + $helperManager->addRoute($route, [__CLASS__, "execute"]); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | public static function execute(AbstractDictBody $knot, $arguments, $methodName) |
45 | 45 | { |
46 | 46 | $methodName = self::convertRouteToPHPFunction($methodName); |
47 | - $data =& $knot->toArray(); |
|
47 | + $data = & $knot->toArray(); |
|
48 | 48 | |
49 | - return call_user_func_array($methodName, array_merge([ &$data ], $arguments)); |
|
49 | + return call_user_func_array($methodName, array_merge([&$data], $arguments)); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function &offsetGet($offset = null) |
31 | 31 | { |
32 | - if ( count(func_get_args()) == 0 or is_null($offset) ) |
|
32 | + if (count(func_get_args()) == 0 or is_null($offset)) |
|
33 | 33 | { |
34 | - $this->data[] = [ ]; |
|
34 | + $this->data[] = []; |
|
35 | 35 | |
36 | 36 | return $this->data[$this->lastKey()]; |
37 | 37 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function offsetSet($offset, $value) |
50 | 50 | { |
51 | - if ( is_null($offset) ) |
|
51 | + if (is_null($offset)) |
|
52 | 52 | { |
53 | 53 | $this->data[] = $value; |
54 | 54 | } |
@@ -51,8 +51,7 @@ |
||
51 | 51 | if ( is_null($offset) ) |
52 | 52 | { |
53 | 53 | $this->data[] = $value; |
54 | - } |
|
55 | - else |
|
54 | + } else |
|
56 | 55 | { |
57 | 56 | $this->data[$offset] = $value; |
58 | 57 | } |