@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * Directives for dump output forwarding. |
31 | 31 | */ |
32 | 32 | public const OUTPUT = 0; |
33 | - public const RETURN = 1; |
|
33 | + public const return = 1; |
|
34 | 34 | public const LOGGER = 2; |
35 | 35 | public const ERROR_LOG = 3; |
36 | 36 | public const OUTPUT_CLI = 4; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | self::OUTPUT => HtmlRenderer::class, |
50 | 50 | self::OUTPUT_CLI => PlainRenderer::class, |
51 | 51 | self::OUTPUT_CLI_COLORS => ConsoleRenderer::class, |
52 | - self::RETURN => HtmlRenderer::class, |
|
52 | + self::return => HtmlRenderer::class, |
|
53 | 53 | self::LOGGER => PlainRenderer::class, |
54 | 54 | self::ERROR_LOG => PlainRenderer::class, |
55 | 55 | self::ROADRUNNER => PlainRenderer::class, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | break; |
95 | 95 | |
96 | 96 | case self::ROADRUNNER: |
97 | - case self::RETURN: |
|
97 | + case self::return: |
|
98 | 98 | return $dump; |
99 | 99 | |
100 | 100 | case self::LOGGER: |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | public function __construct(LoggerInterface $logger = null) |
59 | 59 | { |
60 | - if (!empty($logger)) { |
|
60 | + if (!empty($logger)){ |
|
61 | 61 | $this->setLogger($logger); |
62 | 62 | } |
63 | 63 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $r = $this->getRenderer($target); |
84 | 84 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
85 | 85 | |
86 | - switch ($target) { |
|
86 | + switch ($target){ |
|
87 | 87 | case self::OUTPUT: |
88 | 88 | echo $dump; |
89 | 89 | break; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return $dump; |
94 | 94 | |
95 | 95 | case self::LOGGER: |
96 | - if ($this->logger == null) { |
|
96 | + if ($this->logger == null){ |
|
97 | 97 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface'); |
98 | 98 | } |
99 | 99 | $this->logger->debug($dump); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
116 | 116 | { |
117 | - if (!isset($this->targets[$target])) { |
|
117 | + if (!isset($this->targets[$target])){ |
|
118 | 118 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
119 | 119 | } |
120 | 120 | |
@@ -131,19 +131,19 @@ discard block |
||
131 | 131 | */ |
132 | 132 | private function getRenderer(int $target): RendererInterface |
133 | 133 | { |
134 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
135 | - if (System::isColorsSupported(STDOUT)) { |
|
134 | + if ($target == self::OUTPUT && System::isCLI()){ |
|
135 | + if (System::isColorsSupported(STDOUT)){ |
|
136 | 136 | $target = self::OUTPUT_CLI_COLORS; |
137 | - } else { |
|
137 | + }else{ |
|
138 | 138 | $target = self::OUTPUT_CLI; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | - if (!isset($this->targets[$target])) { |
|
142 | + if (!isset($this->targets[$target])){ |
|
143 | 143 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
144 | 144 | } |
145 | 145 | |
146 | - if (is_string($this->targets[$target])) { |
|
146 | + if (is_string($this->targets[$target])){ |
|
147 | 147 | $this->targets[$target] = new $this->targets[$target](); |
148 | 148 | } |
149 | 149 | |
@@ -166,32 +166,32 @@ discard block |
||
166 | 166 | int $level = 0, |
167 | 167 | bool $hideHeader = false |
168 | 168 | ): string { |
169 | - if (!$hideHeader && !empty($name)) { |
|
170 | - $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
|
171 | - } else { |
|
169 | + if (!$hideHeader && !empty($name)){ |
|
170 | + $header = $r->indent($level).$r->apply($name, 'name').$r->apply(' = ', 'syntax', '='); |
|
171 | + }else{ |
|
172 | 172 | $header = $r->indent($level); |
173 | 173 | } |
174 | 174 | |
175 | - if ($level > $this->maxLevel) { |
|
175 | + if ($level > $this->maxLevel){ |
|
176 | 176 | //Renderer is not reference based, we can't dump too deep values |
177 | - return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
|
177 | + return $r->indent($level).$r->apply('-too deep-', 'maxLevel')."\n"; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $type = strtolower(gettype($value)); |
181 | 181 | |
182 | - if ($type == 'array') { |
|
183 | - return $header . $this->renderArray($r, $value, $level, $hideHeader); |
|
182 | + if ($type == 'array'){ |
|
183 | + return $header.$this->renderArray($r, $value, $level, $hideHeader); |
|
184 | 184 | } |
185 | 185 | |
186 | - if ($type == 'object') { |
|
187 | - return $header . $this->renderObject($r, $value, $level, $hideHeader); |
|
186 | + if ($type == 'object'){ |
|
187 | + return $header.$this->renderObject($r, $value, $level, $hideHeader); |
|
188 | 188 | } |
189 | 189 | |
190 | - if ($type == 'resource') { |
|
190 | + if ($type == 'resource'){ |
|
191 | 191 | //No need to dump resource value |
192 | - $element = get_resource_type($value) . ' resource '; |
|
192 | + $element = get_resource_type($value).' resource '; |
|
193 | 193 | |
194 | - return $header . $r->apply($element, 'type', 'resource') . "\n"; |
|
194 | + return $header.$r->apply($element, 'type', 'resource')."\n"; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | //Value length |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
202 | 202 | |
203 | 203 | $element = null; |
204 | - switch ($type) { |
|
204 | + switch ($type){ |
|
205 | 205 | case 'string': |
206 | 206 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
207 | 207 | break; |
@@ -211,31 +211,31 @@ discard block |
||
211 | 211 | break; |
212 | 212 | |
213 | 213 | default: |
214 | - if ($value !== null) { |
|
214 | + if ($value !== null){ |
|
215 | 215 | //Not showing null value, type is enough |
216 | 216 | $element = var_export($value, true); |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | 220 | //Including value |
221 | - return $header . ' ' . $r->apply($element, 'value', $type) . "\n"; |
|
221 | + return $header.' '.$r->apply($element, 'value', $type)."\n"; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
225 | 225 | { |
226 | - if (!$hideHeader) { |
|
226 | + if (!$hideHeader){ |
|
227 | 227 | $count = count($array); |
228 | 228 | |
229 | 229 | //Array size and scope |
230 | - $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
|
231 | - $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
|
232 | - } else { |
|
230 | + $output = $r->apply("array({$count})", 'type', 'array')."\n"; |
|
231 | + $output .= $r->indent($level).$r->apply('[', 'syntax', '[')."\n"; |
|
232 | + }else{ |
|
233 | 233 | $output = ''; |
234 | 234 | } |
235 | 235 | |
236 | - foreach ($array as $key => $value) { |
|
237 | - if (!is_numeric($key)) { |
|
238 | - if (is_string($key) && $r->escapeStrings()) { |
|
236 | + foreach ($array as $key => $value){ |
|
237 | + if (!is_numeric($key)){ |
|
238 | + if (is_string($key) && $r->escapeStrings()){ |
|
239 | 239 | $key = htmlspecialchars($key); |
240 | 240 | } |
241 | 241 | |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
246 | 246 | } |
247 | 247 | |
248 | - if (!$hideHeader) { |
|
248 | + if (!$hideHeader){ |
|
249 | 249 | //Closing array scope |
250 | - $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
|
250 | + $output .= $r->indent($level).$r->apply(']', 'syntax', ']')."\n"; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | return $output; |
@@ -264,47 +264,47 @@ discard block |
||
264 | 264 | bool $hideHeader = false, |
265 | 265 | string $class = '' |
266 | 266 | ): string { |
267 | - if (!$hideHeader) { |
|
268 | - $type = ($class ?: get_class($value)) . ' object '; |
|
267 | + if (!$hideHeader){ |
|
268 | + $type = ($class ?: get_class($value)).' object '; |
|
269 | 269 | |
270 | - $header = $r->apply($type, 'type', 'object') . "\n"; |
|
271 | - $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
|
272 | - } else { |
|
270 | + $header = $r->apply($type, 'type', 'object')."\n"; |
|
271 | + $header .= $r->indent($level).$r->apply('(', 'syntax', '(')."\n"; |
|
272 | + }else{ |
|
273 | 273 | $header = ''; |
274 | 274 | } |
275 | 275 | |
276 | 276 | //Let's use method specifically created for dumping |
277 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
278 | - if ($value instanceof \Closure) { |
|
277 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure){ |
|
278 | + if ($value instanceof \Closure){ |
|
279 | 279 | $debugInfo = $this->describeClosure($value); |
280 | - } else { |
|
280 | + }else{ |
|
281 | 281 | $debugInfo = $value->__debugInfo(); |
282 | 282 | } |
283 | 283 | |
284 | - if (is_array($debugInfo)) { |
|
284 | + if (is_array($debugInfo)){ |
|
285 | 285 | //Pretty view |
286 | 286 | $debugInfo = (object)$debugInfo; |
287 | 287 | } |
288 | 288 | |
289 | - if (is_object($debugInfo)) { |
|
289 | + if (is_object($debugInfo)){ |
|
290 | 290 | //We are not including syntax elements here |
291 | 291 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
292 | 292 | } |
293 | 293 | |
294 | 294 | return $header |
295 | 295 | . $this->renderValue($r, $debugInfo, '', $level + (is_scalar($value)), true) |
296 | - . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
296 | + . $r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | $refection = new \ReflectionObject($value); |
300 | 300 | |
301 | 301 | $output = ''; |
302 | - foreach ($refection->getProperties() as $property) { |
|
302 | + foreach ($refection->getProperties() as $property){ |
|
303 | 303 | $output .= $this->renderProperty($r, $value, $property, $level); |
304 | 304 | } |
305 | 305 | |
306 | 306 | //Header, content, footer |
307 | - return $header . $output . $r->indent($level) . $r->apply(')', 'syntax', ')') . "\n"; |
|
307 | + return $header.$output.$r->indent($level).$r->apply(')', 'syntax', ')')."\n"; |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
315 | 315 | { |
316 | - if ($p->isStatic()) { |
|
316 | + if ($p->isStatic()){ |
|
317 | 317 | return ''; |
318 | 318 | } |
319 | 319 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | !($value instanceof \stdClass) |
322 | 322 | && is_string($p->getDocComment()) |
323 | 323 | && strpos($p->getDocComment(), '@internal') !== false |
324 | - ) { |
|
324 | + ){ |
|
325 | 325 | // Memory loop while reading doc comment for stdClass variables? |
326 | 326 | // Report a PHP bug about treating comment INSIDE property declaration as doc comment. |
327 | 327 | return ''; |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | //To read private and protected properties |
334 | 334 | $p->setAccessible(true); |
335 | 335 | |
336 | - if ($value instanceof \stdClass) { |
|
336 | + if ($value instanceof \stdClass){ |
|
337 | 337 | $name = $r->apply($p->getName(), 'dynamic'); |
338 | - } else { |
|
338 | + }else{ |
|
339 | 339 | //Property name includes access level |
340 | - $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
|
340 | + $name = $p->getName().$r->apply(':'.$access, 'access', $access); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return $this->renderValue($r, $p->getValue($value), $name, $level + 1); |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | */ |
349 | 349 | private function describeClosure(\Closure $closure): array |
350 | 350 | { |
351 | - try { |
|
351 | + try{ |
|
352 | 352 | $r = new \ReflectionFunction($closure); |
353 | - } catch (\ReflectionException $e) { |
|
353 | + }catch (\ReflectionException $e){ |
|
354 | 354 | return ['closure' => 'unable to resolve']; |
355 | 355 | } |
356 | 356 | |
357 | 357 | return [ |
358 | - 'name' => $r->getName() . " (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
358 | + 'name' => $r->getName()." (lines {$r->getStartLine()}:{$r->getEndLine()})", |
|
359 | 359 | 'file' => $r->getFileName(), |
360 | 360 | 'this' => $r->getClosureThis(), |
361 | 361 | ]; |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | */ |
369 | 369 | private function getAccess(\ReflectionProperty $p): string |
370 | 370 | { |
371 | - if ($p->isPrivate()) { |
|
371 | + if ($p->isPrivate()){ |
|
372 | 372 | return 'private'; |
373 | - } elseif ($p->isProtected()) { |
|
373 | + } elseif ($p->isProtected()){ |
|
374 | 374 | return 'protected'; |
375 | 375 | } |
376 | 376 |
@@ -57,7 +57,8 @@ discard block |
||
57 | 57 | |
58 | 58 | public function __construct(LoggerInterface $logger = null) |
59 | 59 | { |
60 | - if (!empty($logger)) { |
|
60 | + if (!empty($logger)) |
|
61 | + { |
|
61 | 62 | $this->setLogger($logger); |
62 | 63 | } |
63 | 64 | } |
@@ -83,7 +84,8 @@ discard block |
||
83 | 84 | $r = $this->getRenderer($target); |
84 | 85 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
85 | 86 | |
86 | - switch ($target) { |
|
87 | + switch ($target) |
|
88 | + { |
|
87 | 89 | case self::OUTPUT: |
88 | 90 | echo $dump; |
89 | 91 | break; |
@@ -93,7 +95,8 @@ discard block |
||
93 | 95 | return $dump; |
94 | 96 | |
95 | 97 | case self::LOGGER: |
96 | - if ($this->logger == null) { |
|
98 | + if ($this->logger == null) |
|
99 | + { |
|
97 | 100 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface'); |
98 | 101 | } |
99 | 102 | $this->logger->debug($dump); |
@@ -114,7 +117,8 @@ discard block |
||
114 | 117 | */ |
115 | 118 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
116 | 119 | { |
117 | - if (!isset($this->targets[$target])) { |
|
120 | + if (!isset($this->targets[$target])) |
|
121 | + { |
|
118 | 122 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
119 | 123 | } |
120 | 124 | |
@@ -131,19 +135,25 @@ discard block |
||
131 | 135 | */ |
132 | 136 | private function getRenderer(int $target): RendererInterface |
133 | 137 | { |
134 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
135 | - if (System::isColorsSupported(STDOUT)) { |
|
138 | + if ($target == self::OUTPUT && System::isCLI()) |
|
139 | + { |
|
140 | + if (System::isColorsSupported(STDOUT)) |
|
141 | + { |
|
136 | 142 | $target = self::OUTPUT_CLI_COLORS; |
137 | - } else { |
|
143 | + } |
|
144 | + else |
|
145 | + { |
|
138 | 146 | $target = self::OUTPUT_CLI; |
139 | 147 | } |
140 | 148 | } |
141 | 149 | |
142 | - if (!isset($this->targets[$target])) { |
|
150 | + if (!isset($this->targets[$target])) |
|
151 | + { |
|
143 | 152 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
144 | 153 | } |
145 | 154 | |
146 | - if (is_string($this->targets[$target])) { |
|
155 | + if (is_string($this->targets[$target])) |
|
156 | + { |
|
147 | 157 | $this->targets[$target] = new $this->targets[$target](); |
148 | 158 | } |
149 | 159 | |
@@ -166,28 +176,35 @@ discard block |
||
166 | 176 | int $level = 0, |
167 | 177 | bool $hideHeader = false |
168 | 178 | ): string { |
169 | - if (!$hideHeader && !empty($name)) { |
|
179 | + if (!$hideHeader && !empty($name)) |
|
180 | + { |
|
170 | 181 | $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
171 | - } else { |
|
182 | + } |
|
183 | + else |
|
184 | + { |
|
172 | 185 | $header = $r->indent($level); |
173 | 186 | } |
174 | 187 | |
175 | - if ($level > $this->maxLevel) { |
|
188 | + if ($level > $this->maxLevel) |
|
189 | + { |
|
176 | 190 | //Renderer is not reference based, we can't dump too deep values |
177 | 191 | return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
178 | 192 | } |
179 | 193 | |
180 | 194 | $type = strtolower(gettype($value)); |
181 | 195 | |
182 | - if ($type == 'array') { |
|
196 | + if ($type == 'array') |
|
197 | + { |
|
183 | 198 | return $header . $this->renderArray($r, $value, $level, $hideHeader); |
184 | 199 | } |
185 | 200 | |
186 | - if ($type == 'object') { |
|
201 | + if ($type == 'object') |
|
202 | + { |
|
187 | 203 | return $header . $this->renderObject($r, $value, $level, $hideHeader); |
188 | 204 | } |
189 | 205 | |
190 | - if ($type == 'resource') { |
|
206 | + if ($type == 'resource') |
|
207 | + { |
|
191 | 208 | //No need to dump resource value |
192 | 209 | $element = get_resource_type($value) . ' resource '; |
193 | 210 | |
@@ -201,7 +218,8 @@ discard block |
||
201 | 218 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
202 | 219 | |
203 | 220 | $element = null; |
204 | - switch ($type) { |
|
221 | + switch ($type) |
|
222 | + { |
|
205 | 223 | case 'string': |
206 | 224 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
207 | 225 | break; |
@@ -211,7 +229,8 @@ discard block |
||
211 | 229 | break; |
212 | 230 | |
213 | 231 | default: |
214 | - if ($value !== null) { |
|
232 | + if ($value !== null) |
|
233 | + { |
|
215 | 234 | //Not showing null value, type is enough |
216 | 235 | $element = var_export($value, true); |
217 | 236 | } |
@@ -223,19 +242,25 @@ discard block |
||
223 | 242 | |
224 | 243 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
225 | 244 | { |
226 | - if (!$hideHeader) { |
|
245 | + if (!$hideHeader) |
|
246 | + { |
|
227 | 247 | $count = count($array); |
228 | 248 | |
229 | 249 | //Array size and scope |
230 | 250 | $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
231 | 251 | $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
232 | - } else { |
|
252 | + } |
|
253 | + else |
|
254 | + { |
|
233 | 255 | $output = ''; |
234 | 256 | } |
235 | 257 | |
236 | - foreach ($array as $key => $value) { |
|
237 | - if (!is_numeric($key)) { |
|
238 | - if (is_string($key) && $r->escapeStrings()) { |
|
258 | + foreach ($array as $key => $value) |
|
259 | + { |
|
260 | + if (!is_numeric($key)) |
|
261 | + { |
|
262 | + if (is_string($key) && $r->escapeStrings()) |
|
263 | + { |
|
239 | 264 | $key = htmlspecialchars($key); |
240 | 265 | } |
241 | 266 | |
@@ -245,7 +270,8 @@ discard block |
||
245 | 270 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
246 | 271 | } |
247 | 272 | |
248 | - if (!$hideHeader) { |
|
273 | + if (!$hideHeader) |
|
274 | + { |
|
249 | 275 | //Closing array scope |
250 | 276 | $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
251 | 277 | } |
@@ -264,29 +290,38 @@ discard block |
||
264 | 290 | bool $hideHeader = false, |
265 | 291 | string $class = '' |
266 | 292 | ): string { |
267 | - if (!$hideHeader) { |
|
293 | + if (!$hideHeader) |
|
294 | + { |
|
268 | 295 | $type = ($class ?: get_class($value)) . ' object '; |
269 | 296 | |
270 | 297 | $header = $r->apply($type, 'type', 'object') . "\n"; |
271 | 298 | $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
272 | - } else { |
|
299 | + } |
|
300 | + else |
|
301 | + { |
|
273 | 302 | $header = ''; |
274 | 303 | } |
275 | 304 | |
276 | 305 | //Let's use method specifically created for dumping |
277 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
278 | - if ($value instanceof \Closure) { |
|
306 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure) |
|
307 | + { |
|
308 | + if ($value instanceof \Closure) |
|
309 | + { |
|
279 | 310 | $debugInfo = $this->describeClosure($value); |
280 | - } else { |
|
311 | + } |
|
312 | + else |
|
313 | + { |
|
281 | 314 | $debugInfo = $value->__debugInfo(); |
282 | 315 | } |
283 | 316 | |
284 | - if (is_array($debugInfo)) { |
|
317 | + if (is_array($debugInfo)) |
|
318 | + { |
|
285 | 319 | //Pretty view |
286 | 320 | $debugInfo = (object)$debugInfo; |
287 | 321 | } |
288 | 322 | |
289 | - if (is_object($debugInfo)) { |
|
323 | + if (is_object($debugInfo)) |
|
324 | + { |
|
290 | 325 | //We are not including syntax elements here |
291 | 326 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
292 | 327 | } |
@@ -299,7 +334,8 @@ discard block |
||
299 | 334 | $refection = new \ReflectionObject($value); |
300 | 335 | |
301 | 336 | $output = ''; |
302 | - foreach ($refection->getProperties() as $property) { |
|
337 | + foreach ($refection->getProperties() as $property) |
|
338 | + { |
|
303 | 339 | $output .= $this->renderProperty($r, $value, $property, $level); |
304 | 340 | } |
305 | 341 | |
@@ -313,7 +349,8 @@ discard block |
||
313 | 349 | */ |
314 | 350 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
315 | 351 | { |
316 | - if ($p->isStatic()) { |
|
352 | + if ($p->isStatic()) |
|
353 | + { |
|
317 | 354 | return ''; |
318 | 355 | } |
319 | 356 | |
@@ -333,9 +370,12 @@ discard block |
||
333 | 370 | //To read private and protected properties |
334 | 371 | $p->setAccessible(true); |
335 | 372 | |
336 | - if ($value instanceof \stdClass) { |
|
373 | + if ($value instanceof \stdClass) |
|
374 | + { |
|
337 | 375 | $name = $r->apply($p->getName(), 'dynamic'); |
338 | - } else { |
|
376 | + } |
|
377 | + else |
|
378 | + { |
|
339 | 379 | //Property name includes access level |
340 | 380 | $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
341 | 381 | } |
@@ -348,9 +388,12 @@ discard block |
||
348 | 388 | */ |
349 | 389 | private function describeClosure(\Closure $closure): array |
350 | 390 | { |
351 | - try { |
|
391 | + try |
|
392 | + { |
|
352 | 393 | $r = new \ReflectionFunction($closure); |
353 | - } catch (\ReflectionException $e) { |
|
394 | + } |
|
395 | + catch (\ReflectionException $e) |
|
396 | + { |
|
354 | 397 | return ['closure' => 'unable to resolve']; |
355 | 398 | } |
356 | 399 | |
@@ -368,9 +411,12 @@ discard block |
||
368 | 411 | */ |
369 | 412 | private function getAccess(\ReflectionProperty $p): string |
370 | 413 | { |
371 | - if ($p->isPrivate()) { |
|
414 | + if ($p->isPrivate()) |
|
415 | + { |
|
372 | 416 | return 'private'; |
373 | - } elseif ($p->isProtected()) { |
|
417 | + } |
|
418 | + elseif ($p->isProtected()) |
|
419 | + { |
|
374 | 420 | return 'protected'; |
375 | 421 | } |
376 | 422 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | string $method, |
42 | 42 | array $args = [], |
43 | 43 | ?string $message = null |
44 | - ) { |
|
44 | + ){ |
|
45 | 45 | $this->checker = $checker; |
46 | 46 | $this->method = $method; |
47 | 47 | $this->args = $args; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function getMessage(string $field, $value): string |
71 | 71 | { |
72 | - if (!empty($this->message)) { |
|
72 | + if (!empty($this->message)){ |
|
73 | 73 | return $this->say( |
74 | 74 | $this->message, |
75 | 75 | array_merge([$value, $field], $this->args) |
@@ -69,7 +69,8 @@ |
||
69 | 69 | */ |
70 | 70 | public function getMessage(string $field, $value): string |
71 | 71 | { |
72 | - if (!empty($this->message)) { |
|
72 | + if (!empty($this->message)) |
|
73 | + { |
|
73 | 74 | return $this->say( |
74 | 75 | $this->message, |
75 | 76 | array_merge([$value, $field], $this->args) |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(SpecificationInterface $expression) |
21 | 21 | { |
22 | - if (!$expression instanceof AbstractSorter) { |
|
22 | + if (!$expression instanceof AbstractSorter){ |
|
23 | 23 | throw new \LogicException('Only sorters allowed'); |
24 | 24 | } |
25 | 25 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | { |
34 | 34 | $injector = static::INJECTION; |
35 | 35 | |
36 | - if (!class_exists($injector)) { |
|
36 | + if (!class_exists($injector)){ |
|
37 | 37 | throw new \LogicException( |
38 | 38 | sprintf('Class "%s" does not exist', $injector) |
39 | 39 | ); |
40 | 40 | } |
41 | 41 | |
42 | - if (!is_subclass_of($injector, FragmentInterface::class)) { |
|
42 | + if (!is_subclass_of($injector, FragmentInterface::class)){ |
|
43 | 43 | throw new \LogicException( |
44 | 44 | 'INJECTION class does not implement FragmentInterface' |
45 | 45 | ); |
@@ -19,7 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(SpecificationInterface $expression) |
21 | 21 | { |
22 | - if (!$expression instanceof AbstractSorter) { |
|
22 | + if (!$expression instanceof AbstractSorter) |
|
23 | + { |
|
23 | 24 | throw new \LogicException('Only sorters allowed'); |
24 | 25 | } |
25 | 26 | |
@@ -33,13 +34,15 @@ discard block |
||
33 | 34 | { |
34 | 35 | $injector = static::INJECTION; |
35 | 36 | |
36 | - if (!class_exists($injector)) { |
|
37 | + if (!class_exists($injector)) |
|
38 | + { |
|
37 | 39 | throw new \LogicException( |
38 | 40 | sprintf('Class "%s" does not exist', $injector) |
39 | 41 | ); |
40 | 42 | } |
41 | 43 | |
42 | - if (!is_subclass_of($injector, FragmentInterface::class)) { |
|
44 | + if (!is_subclass_of($injector, FragmentInterface::class)) |
|
45 | + { |
|
43 | 46 | throw new \LogicException( |
44 | 47 | 'INJECTION class does not implement FragmentInterface' |
45 | 48 | ); |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
55 | 55 | { |
56 | - if (!$this->targetAcceptable($source)) { |
|
56 | + if (!$this->targetAcceptable($source)){ |
|
57 | 57 | return null; |
58 | 58 | } |
59 | 59 | |
60 | - if ($specification instanceof Specification\FilterInterface) { |
|
60 | + if ($specification instanceof Specification\FilterInterface){ |
|
61 | 61 | return $this->writeFilter($source, $specification, $compiler); |
62 | 62 | } |
63 | 63 | |
64 | - if ($specification instanceof Specification\SorterInterface) { |
|
64 | + if ($specification instanceof Specification\SorterInterface){ |
|
65 | 65 | return $this->writeSorter($source, $specification, $compiler); |
66 | 66 | } |
67 | 67 | |
68 | - if ($specification instanceof Specification\Pagination\Limit) { |
|
68 | + if ($specification instanceof Specification\Pagination\Limit){ |
|
69 | 69 | return $source->limit($specification->getValue()); |
70 | 70 | } |
71 | 71 | |
72 | - if ($specification instanceof Specification\Pagination\Offset) { |
|
72 | + if ($specification instanceof Specification\Pagination\Offset){ |
|
73 | 73 | return $source->offset($specification->getValue()); |
74 | 74 | } |
75 | 75 | |
@@ -84,15 +84,15 @@ discard block |
||
84 | 84 | */ |
85 | 85 | protected function writeFilter($source, Specification\FilterInterface $filter, Compiler $compiler) |
86 | 86 | { |
87 | - if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) { |
|
87 | + if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map){ |
|
88 | 88 | return $source->where(static function () use ($compiler, $filter, $source): void { |
89 | 89 | $compiler->compile($source, ...$filter->getFilters()); |
90 | 90 | }); |
91 | 91 | } |
92 | 92 | |
93 | - if ($filter instanceof Specification\Filter\Any) { |
|
93 | + if ($filter instanceof Specification\Filter\Any){ |
|
94 | 94 | return $source->where(static function () use ($compiler, $filter, $source): void { |
95 | - foreach ($filter->getFilters() as $subFilter) { |
|
95 | + foreach ($filter->getFilters() as $subFilter){ |
|
96 | 96 | $source->orWhere(static function () use ($compiler, $subFilter, $source): void { |
97 | 97 | $compiler->compile($source, $subFilter); |
98 | 98 | }); |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | }); |
101 | 101 | } |
102 | 102 | |
103 | - if ($filter instanceof Specification\Filter\InjectionFilter) { |
|
103 | + if ($filter instanceof Specification\Filter\InjectionFilter){ |
|
104 | 104 | $expression = $filter->getFilter(); |
105 | - if ($expression instanceof Specification\Filter\Expression) { |
|
105 | + if ($expression instanceof Specification\Filter\Expression){ |
|
106 | 106 | return $source->where( |
107 | 107 | $filter->getInjection(), |
108 | 108 | $this->getExpressionOperator($expression), |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - if ($filter instanceof Specification\Filter\Expression) { |
|
114 | + if ($filter instanceof Specification\Filter\Expression){ |
|
115 | 115 | return $source->where( |
116 | 116 | $filter->getExpression(), |
117 | 117 | $this->getExpressionOperator($filter), |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | */ |
129 | 129 | protected function getExpressionOperator(Specification\Filter\Expression $filter): string |
130 | 130 | { |
131 | - if ($filter instanceof Specification\Filter\Like) { |
|
131 | + if ($filter instanceof Specification\Filter\Like){ |
|
132 | 132 | return 'LIKE'; |
133 | 133 | } |
134 | 134 | |
135 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
135 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
136 | 136 | return static::ARRAY_OPERATORS[get_class($filter)]; |
137 | 137 | } |
138 | 138 | |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | */ |
146 | 146 | protected function getExpressionArgs(Specification\Filter\Expression $filter): array |
147 | 147 | { |
148 | - if ($filter instanceof Specification\Filter\Like) { |
|
148 | + if ($filter instanceof Specification\Filter\Like){ |
|
149 | 149 | return [sprintf($filter->getPattern(), $this->fetchValue($filter->getValue()))]; |
150 | 150 | } |
151 | 151 | |
152 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
152 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray){ |
|
153 | 153 | return [new Parameter($this->fetchValue($filter->getValue()))]; |
154 | 154 | } |
155 | 155 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | */ |
165 | 165 | protected function writeSorter($source, Specification\SorterInterface $sorter, Compiler $compiler) |
166 | 166 | { |
167 | - if ($sorter instanceof Specification\Sorter\SorterSet) { |
|
168 | - foreach ($sorter->getSorters() as $subSorter) { |
|
167 | + if ($sorter instanceof Specification\Sorter\SorterSet){ |
|
168 | + foreach ($sorter->getSorters() as $subSorter){ |
|
169 | 169 | $source = $compiler->compile($source, $subSorter); |
170 | 170 | } |
171 | 171 | |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | if ( |
176 | 176 | $sorter instanceof Specification\Sorter\AscSorter |
177 | 177 | || $sorter instanceof Specification\Sorter\DescSorter |
178 | - ) { |
|
178 | + ){ |
|
179 | 179 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)]; |
180 | - foreach ($sorter->getExpressions() as $expression) { |
|
180 | + foreach ($sorter->getExpressions() as $expression){ |
|
181 | 181 | $source = $source->orderBy($expression, $direction); |
182 | 182 | } |
183 | 183 | |
184 | 184 | return $source; |
185 | 185 | } |
186 | 186 | |
187 | - if ($sorter instanceof InjectionSorter) { |
|
187 | + if ($sorter instanceof InjectionSorter){ |
|
188 | 188 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)] ?? 'ASC'; |
189 | - foreach ($sorter->getInjections() as $injection) { |
|
189 | + foreach ($sorter->getInjections() as $injection){ |
|
190 | 190 | $source = $source->orderBy($injection, $direction); |
191 | 191 | } |
192 | 192 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function fetchValue($value) |
206 | 206 | { |
207 | - if ($value instanceof Specification\ValueInterface) { |
|
207 | + if ($value instanceof Specification\ValueInterface){ |
|
208 | 208 | throw new CompilerException('Value expects user input, none given'); |
209 | 209 | } |
210 | 210 | |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | */ |
218 | 218 | protected function targetAcceptable($target): bool |
219 | 219 | { |
220 | - if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) { |
|
220 | + if (class_exists(SelectQuery::class) && $target instanceof SelectQuery){ |
|
221 | 221 | return true; |
222 | 222 | } |
223 | 223 | |
224 | - if (class_exists(Select::class) && $target instanceof Select) { |
|
224 | + if (class_exists(Select::class) && $target instanceof Select){ |
|
225 | 225 | return true; |
226 | 226 | } |
227 | 227 |
@@ -53,23 +53,28 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function write($source, SpecificationInterface $specification, Compiler $compiler) |
55 | 55 | { |
56 | - if (!$this->targetAcceptable($source)) { |
|
56 | + if (!$this->targetAcceptable($source)) |
|
57 | + { |
|
57 | 58 | return null; |
58 | 59 | } |
59 | 60 | |
60 | - if ($specification instanceof Specification\FilterInterface) { |
|
61 | + if ($specification instanceof Specification\FilterInterface) |
|
62 | + { |
|
61 | 63 | return $this->writeFilter($source, $specification, $compiler); |
62 | 64 | } |
63 | 65 | |
64 | - if ($specification instanceof Specification\SorterInterface) { |
|
66 | + if ($specification instanceof Specification\SorterInterface) |
|
67 | + { |
|
65 | 68 | return $this->writeSorter($source, $specification, $compiler); |
66 | 69 | } |
67 | 70 | |
68 | - if ($specification instanceof Specification\Pagination\Limit) { |
|
71 | + if ($specification instanceof Specification\Pagination\Limit) |
|
72 | + { |
|
69 | 73 | return $source->limit($specification->getValue()); |
70 | 74 | } |
71 | 75 | |
72 | - if ($specification instanceof Specification\Pagination\Offset) { |
|
76 | + if ($specification instanceof Specification\Pagination\Offset) |
|
77 | + { |
|
73 | 78 | return $source->offset($specification->getValue()); |
74 | 79 | } |
75 | 80 | |
@@ -84,15 +89,18 @@ discard block |
||
84 | 89 | */ |
85 | 90 | protected function writeFilter($source, Specification\FilterInterface $filter, Compiler $compiler) |
86 | 91 | { |
87 | - if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) { |
|
92 | + if ($filter instanceof Specification\Filter\All || $filter instanceof Specification\Filter\Map) |
|
93 | + { |
|
88 | 94 | return $source->where(static function () use ($compiler, $filter, $source): void { |
89 | 95 | $compiler->compile($source, ...$filter->getFilters()); |
90 | 96 | }); |
91 | 97 | } |
92 | 98 | |
93 | - if ($filter instanceof Specification\Filter\Any) { |
|
99 | + if ($filter instanceof Specification\Filter\Any) |
|
100 | + { |
|
94 | 101 | return $source->where(static function () use ($compiler, $filter, $source): void { |
95 | - foreach ($filter->getFilters() as $subFilter) { |
|
102 | + foreach ($filter->getFilters() as $subFilter) |
|
103 | + { |
|
96 | 104 | $source->orWhere(static function () use ($compiler, $subFilter, $source): void { |
97 | 105 | $compiler->compile($source, $subFilter); |
98 | 106 | }); |
@@ -100,9 +108,11 @@ discard block |
||
100 | 108 | }); |
101 | 109 | } |
102 | 110 | |
103 | - if ($filter instanceof Specification\Filter\InjectionFilter) { |
|
111 | + if ($filter instanceof Specification\Filter\InjectionFilter) |
|
112 | + { |
|
104 | 113 | $expression = $filter->getFilter(); |
105 | - if ($expression instanceof Specification\Filter\Expression) { |
|
114 | + if ($expression instanceof Specification\Filter\Expression) |
|
115 | + { |
|
106 | 116 | return $source->where( |
107 | 117 | $filter->getInjection(), |
108 | 118 | $this->getExpressionOperator($expression), |
@@ -111,7 +121,8 @@ discard block |
||
111 | 121 | } |
112 | 122 | } |
113 | 123 | |
114 | - if ($filter instanceof Specification\Filter\Expression) { |
|
124 | + if ($filter instanceof Specification\Filter\Expression) |
|
125 | + { |
|
115 | 126 | return $source->where( |
116 | 127 | $filter->getExpression(), |
117 | 128 | $this->getExpressionOperator($filter), |
@@ -128,11 +139,13 @@ discard block |
||
128 | 139 | */ |
129 | 140 | protected function getExpressionOperator(Specification\Filter\Expression $filter): string |
130 | 141 | { |
131 | - if ($filter instanceof Specification\Filter\Like) { |
|
142 | + if ($filter instanceof Specification\Filter\Like) |
|
143 | + { |
|
132 | 144 | return 'LIKE'; |
133 | 145 | } |
134 | 146 | |
135 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
147 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) |
|
148 | + { |
|
136 | 149 | return static::ARRAY_OPERATORS[get_class($filter)]; |
137 | 150 | } |
138 | 151 | |
@@ -145,11 +158,13 @@ discard block |
||
145 | 158 | */ |
146 | 159 | protected function getExpressionArgs(Specification\Filter\Expression $filter): array |
147 | 160 | { |
148 | - if ($filter instanceof Specification\Filter\Like) { |
|
161 | + if ($filter instanceof Specification\Filter\Like) |
|
162 | + { |
|
149 | 163 | return [sprintf($filter->getPattern(), $this->fetchValue($filter->getValue()))]; |
150 | 164 | } |
151 | 165 | |
152 | - if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) { |
|
166 | + if ($filter instanceof Specification\Filter\InArray || $filter instanceof Specification\Filter\NotInArray) |
|
167 | + { |
|
153 | 168 | return [new Parameter($this->fetchValue($filter->getValue()))]; |
154 | 169 | } |
155 | 170 | |
@@ -164,8 +179,10 @@ discard block |
||
164 | 179 | */ |
165 | 180 | protected function writeSorter($source, Specification\SorterInterface $sorter, Compiler $compiler) |
166 | 181 | { |
167 | - if ($sorter instanceof Specification\Sorter\SorterSet) { |
|
168 | - foreach ($sorter->getSorters() as $subSorter) { |
|
182 | + if ($sorter instanceof Specification\Sorter\SorterSet) |
|
183 | + { |
|
184 | + foreach ($sorter->getSorters() as $subSorter) |
|
185 | + { |
|
169 | 186 | $source = $compiler->compile($source, $subSorter); |
170 | 187 | } |
171 | 188 | |
@@ -177,16 +194,19 @@ discard block |
||
177 | 194 | || $sorter instanceof Specification\Sorter\DescSorter |
178 | 195 | ) { |
179 | 196 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)]; |
180 | - foreach ($sorter->getExpressions() as $expression) { |
|
197 | + foreach ($sorter->getExpressions() as $expression) |
|
198 | + { |
|
181 | 199 | $source = $source->orderBy($expression, $direction); |
182 | 200 | } |
183 | 201 | |
184 | 202 | return $source; |
185 | 203 | } |
186 | 204 | |
187 | - if ($sorter instanceof InjectionSorter) { |
|
205 | + if ($sorter instanceof InjectionSorter) |
|
206 | + { |
|
188 | 207 | $direction = static::SORTER_DIRECTIONS[get_class($sorter)] ?? 'ASC'; |
189 | - foreach ($sorter->getInjections() as $injection) { |
|
208 | + foreach ($sorter->getInjections() as $injection) |
|
209 | + { |
|
190 | 210 | $source = $source->orderBy($injection, $direction); |
191 | 211 | } |
192 | 212 | |
@@ -204,7 +224,8 @@ discard block |
||
204 | 224 | */ |
205 | 225 | protected function fetchValue($value) |
206 | 226 | { |
207 | - if ($value instanceof Specification\ValueInterface) { |
|
227 | + if ($value instanceof Specification\ValueInterface) |
|
228 | + { |
|
208 | 229 | throw new CompilerException('Value expects user input, none given'); |
209 | 230 | } |
210 | 231 | |
@@ -217,11 +238,13 @@ discard block |
||
217 | 238 | */ |
218 | 239 | protected function targetAcceptable($target): bool |
219 | 240 | { |
220 | - if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) { |
|
241 | + if (class_exists(SelectQuery::class) && $target instanceof SelectQuery) |
|
242 | + { |
|
221 | 243 | return true; |
222 | 244 | } |
223 | 245 | |
224 | - if (class_exists(Select::class) && $target instanceof Select) { |
|
246 | + if (class_exists(Select::class) && $target instanceof Select) |
|
247 | + { |
|
225 | 248 | return true; |
226 | 249 | } |
227 | 250 |
@@ -26,14 +26,14 @@ |
||
26 | 26 | public function setUp(): void |
27 | 27 | { |
28 | 28 | $this->app = App::init([ |
29 | - 'root' => __DIR__ . '/App', |
|
30 | - 'app' => __DIR__ . '/App' |
|
29 | + 'root' => __DIR__.'/App', |
|
30 | + 'app' => __DIR__.'/App' |
|
31 | 31 | ]); |
32 | 32 | } |
33 | 33 | |
34 | 34 | public function tearDown(): void |
35 | 35 | { |
36 | - foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) { |
|
36 | + foreach (glob(__DIR__.'/App/runtime/cache/views/*.php') as $file){ |
|
37 | 37 | @unlink($file); |
38 | 38 | } |
39 | 39 | } |
@@ -33,7 +33,8 @@ |
||
33 | 33 | |
34 | 34 | public function tearDown(): void |
35 | 35 | { |
36 | - foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) { |
|
36 | + foreach (glob(__DIR__ . '/App/runtime/cache/views/*.php') as $file) |
|
37 | + { |
|
37 | 38 | @unlink($file); |
38 | 39 | } |
39 | 40 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | ReaderInterface $reader, |
33 | 33 | CacheItemPoolInterface $cache, |
34 | 34 | KeyGeneratorInterface $generator = null |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | $this->cache = $cache; |
37 | 37 | |
38 | 38 | parent::__construct($reader, $generator); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $item = $this->cache->getItem($key); |
48 | 48 | |
49 | - if (!$item->isHit()) { |
|
49 | + if (!$item->isHit()){ |
|
50 | 50 | $this->cache->save( |
51 | 51 | $item->set($then()) |
52 | 52 | ); |
@@ -46,7 +46,8 @@ |
||
46 | 46 | { |
47 | 47 | $item = $this->cache->getItem($key); |
48 | 48 | |
49 | - if (!$item->isHit()) { |
|
49 | + if (!$item->isHit()) |
|
50 | + { |
|
50 | 51 | $this->cache->save( |
51 | 52 | $item->set($then()) |
52 | 53 | ); |
@@ -41,7 +41,7 @@ |
||
41 | 41 | */ |
42 | 42 | protected function cached(string $key, callable $then): iterable |
43 | 43 | { |
44 | - if (!$this->cache->has($key)) { |
|
44 | + if (!$this->cache->has($key)){ |
|
45 | 45 | $this->cache->set($key, $then()); |
46 | 46 | } |
47 | 47 |
@@ -41,7 +41,8 @@ |
||
41 | 41 | */ |
42 | 42 | protected function cached(string $key, callable $then): iterable |
43 | 43 | { |
44 | - if (!$this->cache->has($key)) { |
|
44 | + if (!$this->cache->has($key)) |
|
45 | + { |
|
45 | 46 | $this->cache->set($key, $then()); |
46 | 47 | } |
47 | 48 |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
36 | 36 | { |
37 | - if ($this->isNamedArgumentsSupported()) { |
|
38 | - try { |
|
37 | + if ($this->isNamedArgumentsSupported()){ |
|
38 | + try{ |
|
39 | 39 | return $attr->newInstanceArgs($arguments); |
40 | - } catch (\Throwable $e) { |
|
40 | + }catch (\Throwable $e){ |
|
41 | 41 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
45 | 45 | $constructor = $this->getConstructor($attr); |
46 | 46 | |
47 | - if ($constructor === null) { |
|
47 | + if ($constructor === null){ |
|
48 | 48 | return $attr->newInstanceWithoutConstructor(); |
49 | 49 | } |
50 | 50 | |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | { |
73 | 73 | $passed = []; |
74 | 74 | |
75 | - try { |
|
76 | - foreach ($constructor->getParameters() as $parameter) { |
|
75 | + try{ |
|
76 | + foreach ($constructor->getParameters() as $parameter){ |
|
77 | 77 | $passed[] = $this->resolveParameter($ctx, $parameter, $arguments); |
78 | 78 | } |
79 | 79 | |
80 | - if (\count($arguments)) { |
|
80 | + if (\count($arguments)){ |
|
81 | 81 | $message = \sprintf(self::ERROR_UNKNOWN_ARGUMENT, \array_key_first($arguments)); |
82 | 82 | throw new \BadMethodCallException($message); |
83 | 83 | } |
84 | - } catch (\Throwable $e) { |
|
84 | + }catch (\Throwable $e){ |
|
85 | 85 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
86 | 86 | } |
87 | 87 | |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | */ |
98 | 98 | private function resolveParameter(\ReflectionClass $ctx, \ReflectionParameter $param, array &$arguments) |
99 | 99 | { |
100 | - switch (true) { |
|
100 | + switch (true){ |
|
101 | 101 | case \array_key_exists($param->getName(), $arguments): |
102 | - try { |
|
102 | + try{ |
|
103 | 103 | return $arguments[$param->getName()]; |
104 | - } finally { |
|
104 | + }finally{ |
|
105 | 105 | unset($arguments[$param->getName()]); |
106 | 106 | } |
107 | 107 | // no actual falling through |
108 | 108 | |
109 | 109 | case \array_key_exists($param->getPosition(), $arguments): |
110 | - try { |
|
110 | + try{ |
|
111 | 111 | return $arguments[$param->getPosition()]; |
112 | - } finally { |
|
112 | + }finally{ |
|
113 | 113 | unset($arguments[$param->getPosition()]); |
114 | 114 | } |
115 | 115 | // no actual falling through |
@@ -34,17 +34,22 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
36 | 36 | { |
37 | - if ($this->isNamedArgumentsSupported()) { |
|
38 | - try { |
|
37 | + if ($this->isNamedArgumentsSupported()) |
|
38 | + { |
|
39 | + try |
|
40 | + { |
|
39 | 41 | return $attr->newInstanceArgs($arguments); |
40 | - } catch (\Throwable $e) { |
|
42 | + } |
|
43 | + catch (\Throwable $e) |
|
44 | + { |
|
41 | 45 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
42 | 46 | } |
43 | 47 | } |
44 | 48 | |
45 | 49 | $constructor = $this->getConstructor($attr); |
46 | 50 | |
47 | - if ($constructor === null) { |
|
51 | + if ($constructor === null) |
|
52 | + { |
|
48 | 53 | return $attr->newInstanceWithoutConstructor(); |
49 | 54 | } |
50 | 55 | |
@@ -72,16 +77,21 @@ discard block |
||
72 | 77 | { |
73 | 78 | $passed = []; |
74 | 79 | |
75 | - try { |
|
76 | - foreach ($constructor->getParameters() as $parameter) { |
|
80 | + try |
|
81 | + { |
|
82 | + foreach ($constructor->getParameters() as $parameter) |
|
83 | + { |
|
77 | 84 | $passed[] = $this->resolveParameter($ctx, $parameter, $arguments); |
78 | 85 | } |
79 | 86 | |
80 | - if (\count($arguments)) { |
|
87 | + if (\count($arguments)) |
|
88 | + { |
|
81 | 89 | $message = \sprintf(self::ERROR_UNKNOWN_ARGUMENT, \array_key_first($arguments)); |
82 | 90 | throw new \BadMethodCallException($message); |
83 | 91 | } |
84 | - } catch (\Throwable $e) { |
|
92 | + } |
|
93 | + catch (\Throwable $e) |
|
94 | + { |
|
85 | 95 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
86 | 96 | } |
87 | 97 | |
@@ -97,19 +107,26 @@ discard block |
||
97 | 107 | */ |
98 | 108 | private function resolveParameter(\ReflectionClass $ctx, \ReflectionParameter $param, array &$arguments) |
99 | 109 | { |
100 | - switch (true) { |
|
110 | + switch (true) |
|
111 | + { |
|
101 | 112 | case \array_key_exists($param->getName(), $arguments): |
102 | - try { |
|
113 | + try |
|
114 | + { |
|
103 | 115 | return $arguments[$param->getName()]; |
104 | - } finally { |
|
116 | + } |
|
117 | + finally |
|
118 | + { |
|
105 | 119 | unset($arguments[$param->getName()]); |
106 | 120 | } |
107 | 121 | // no actual falling through |
108 | 122 | |
109 | 123 | case \array_key_exists($param->getPosition(), $arguments): |
110 | - try { |
|
124 | + try |
|
125 | + { |
|
111 | 126 | return $arguments[$param->getPosition()]; |
112 | - } finally { |
|
127 | + } |
|
128 | + finally |
|
129 | + { |
|
113 | 130 | unset($arguments[$param->getPosition()]); |
114 | 131 | } |
115 | 132 | // no actual falling through |
@@ -124,7 +124,7 @@ |
||
124 | 124 | */ |
125 | 125 | protected function iterableToArray(iterable $attributes): array |
126 | 126 | { |
127 | - if ($attributes instanceof \Traversable) { |
|
127 | + if ($attributes instanceof \Traversable){ |
|
128 | 128 | return \iterator_to_array($attributes, false); |
129 | 129 | } |
130 | 130 |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function getClassMetadata(\ReflectionClass $class, string $name = null): iterable |
43 | 43 | { |
44 | - $result = $this->cached($this->key->forClass($class), function () use ($class) { |
|
44 | + $result = $this->cached($this->key->forClass($class), function () use ($class) |
|
45 | + { |
|
45 | 46 | return $this->iterableToArray(parent::getClassMetadata($class)); |
46 | 47 | }); |
47 | 48 | |
@@ -53,7 +54,8 @@ discard block |
||
53 | 54 | */ |
54 | 55 | public function getFunctionMetadata(\ReflectionFunctionAbstract $function, string $name = null): iterable |
55 | 56 | { |
56 | - $result = $this->cached($this->key->forFunction($function), function () use ($function) { |
|
57 | + $result = $this->cached($this->key->forFunction($function), function () use ($function) |
|
58 | + { |
|
57 | 59 | return $this->iterableToArray(parent::getFunctionMetadata($function)); |
58 | 60 | }); |
59 | 61 | |
@@ -65,7 +67,8 @@ discard block |
||
65 | 67 | */ |
66 | 68 | public function getPropertyMetadata(\ReflectionProperty $property, string $name = null): iterable |
67 | 69 | { |
68 | - $result = $this->cached($this->key->forProperty($property), function () use ($property) { |
|
70 | + $result = $this->cached($this->key->forProperty($property), function () use ($property) |
|
71 | + { |
|
69 | 72 | return $this->iterableToArray(parent::getPropertyMetadata($property)); |
70 | 73 | }); |
71 | 74 | |
@@ -77,7 +80,8 @@ discard block |
||
77 | 80 | */ |
78 | 81 | public function getConstantMetadata(\ReflectionClassConstant $constant, string $name = null): iterable |
79 | 82 | { |
80 | - $result = $this->cached($this->key->forConstant($constant), function () use ($constant) { |
|
83 | + $result = $this->cached($this->key->forConstant($constant), function () use ($constant) |
|
84 | + { |
|
81 | 85 | return $this->iterableToArray(parent::getConstantMetadata($constant)); |
82 | 86 | }); |
83 | 87 | |
@@ -89,7 +93,8 @@ discard block |
||
89 | 93 | */ |
90 | 94 | public function getParameterMetadata(\ReflectionParameter $parameter, string $name = null): iterable |
91 | 95 | { |
92 | - $result = $this->cached($this->key->forParameter($parameter), function () use ($parameter) { |
|
96 | + $result = $this->cached($this->key->forParameter($parameter), function () use ($parameter) |
|
97 | + { |
|
93 | 98 | return $this->iterableToArray(parent::getParameterMetadata($parameter)); |
94 | 99 | }); |
95 | 100 | |
@@ -124,7 +129,8 @@ discard block |
||
124 | 129 | */ |
125 | 130 | protected function iterableToArray(iterable $attributes): array |
126 | 131 | { |
127 | - if ($attributes instanceof \Traversable) { |
|
132 | + if ($attributes instanceof \Traversable) |
|
133 | + { |
|
128 | 134 | return \iterator_to_array($attributes, false); |
129 | 135 | } |
130 | 136 |