@@ -25,16 +25,16 @@ |
||
25 | 25 | */ |
26 | 26 | public function enterNode(Node $node) |
27 | 27 | { |
28 | - if ($node instanceof Node\Stmt\Class_) { |
|
29 | - foreach ($node->stmts as $stmt) { |
|
30 | - if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct') { |
|
28 | + if ($node instanceof Node\Stmt\Class_){ |
|
29 | + foreach ($node->stmts as $stmt){ |
|
30 | + if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct'){ |
|
31 | 31 | return $stmt; |
32 | 32 | } |
33 | 33 | } |
34 | 34 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
35 | 35 | } |
36 | 36 | |
37 | - if ($node instanceof Node\Expr\Variable) { |
|
37 | + if ($node instanceof Node\Expr\Variable){ |
|
38 | 38 | $this->vars[] = $node->name; |
39 | 39 | } |
40 | 40 |
@@ -25,16 +25,20 @@ |
||
25 | 25 | */ |
26 | 26 | public function enterNode(Node $node) |
27 | 27 | { |
28 | - if ($node instanceof Node\Stmt\Class_) { |
|
29 | - foreach ($node->stmts as $stmt) { |
|
30 | - if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct') { |
|
28 | + if ($node instanceof Node\Stmt\Class_) |
|
29 | + { |
|
30 | + foreach ($node->stmts as $stmt) |
|
31 | + { |
|
32 | + if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name === '__construct') |
|
33 | + { |
|
31 | 34 | return $stmt; |
32 | 35 | } |
33 | 36 | } |
34 | 37 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
35 | 38 | } |
36 | 39 | |
37 | - if ($node instanceof Node\Expr\Variable) { |
|
40 | + if ($node instanceof Node\Expr\Variable) |
|
41 | + { |
|
38 | 42 | $this->vars[] = $node->name; |
39 | 43 | } |
40 | 44 |
@@ -39,7 +39,8 @@ |
||
39 | 39 | */ |
40 | 40 | public function process(ViewSource $source, ContextInterface $context): ViewSource |
41 | 41 | { |
42 | - return $source->withCode(preg_replace_callback($this->pattern, static function ($matches) use ($context) { |
|
42 | + return $source->withCode(preg_replace_callback($this->pattern, static function ($matches) use ($context) |
|
43 | + { |
|
43 | 44 | return $context->resolveValue($matches[1]); |
44 | 45 | }, $source->getCode())); |
45 | 46 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __destruct() |
47 | 47 | { |
48 | - foreach ($this->destructFiles as $filename) { |
|
48 | + foreach ($this->destructFiles as $filename){ |
|
49 | 49 | $this->delete($filename); |
50 | 50 | } |
51 | 51 | } |
@@ -60,30 +60,30 @@ discard block |
||
60 | 60 | int $mode = null, |
61 | 61 | bool $recursivePermissions = true |
62 | 62 | ): bool { |
63 | - if (empty($mode)) { |
|
63 | + if (empty($mode)){ |
|
64 | 64 | $mode = self::DEFAULT_FILE_MODE; |
65 | 65 | } |
66 | 66 | |
67 | 67 | //Directories always executable |
68 | 68 | $mode = $mode | 0111; |
69 | - if (is_dir($directory)) { |
|
69 | + if (is_dir($directory)){ |
|
70 | 70 | //Exists :( |
71 | 71 | return $this->setPermissions($directory, $mode); |
72 | 72 | } |
73 | 73 | |
74 | - if (!$recursivePermissions) { |
|
74 | + if (!$recursivePermissions){ |
|
75 | 75 | return mkdir($directory, $mode, true); |
76 | 76 | } |
77 | 77 | |
78 | 78 | $directoryChain = [basename($directory)]; |
79 | 79 | |
80 | 80 | $baseDirectory = $directory; |
81 | - while (!is_dir($baseDirectory = dirname($baseDirectory))) { |
|
81 | + while (!is_dir($baseDirectory = dirname($baseDirectory))){ |
|
82 | 82 | $directoryChain[] = basename($baseDirectory); |
83 | 83 | } |
84 | 84 | |
85 | - foreach (array_reverse($directoryChain) as $directory) { |
|
86 | - if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) { |
|
85 | + foreach (array_reverse($directoryChain) as $directory){ |
|
86 | + if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")){ |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function read(string $filename): string |
100 | 100 | { |
101 | - if (!$this->exists($filename)) { |
|
101 | + if (!$this->exists($filename)){ |
|
102 | 102 | throw new FileNotFoundException($filename); |
103 | 103 | } |
104 | 104 | |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | ): bool { |
120 | 120 | $mode = $mode ?? self::DEFAULT_FILE_MODE; |
121 | 121 | |
122 | - try { |
|
123 | - if ($ensureDirectory) { |
|
122 | + try{ |
|
123 | + if ($ensureDirectory){ |
|
124 | 124 | $this->ensureDirectory(dirname($filename), $mode); |
125 | 125 | } |
126 | 126 | |
127 | - if ($this->exists($filename)) { |
|
127 | + if ($this->exists($filename)){ |
|
128 | 128 | //Forcing mode for existed file |
129 | 129 | $this->setPermissions($filename, $mode); |
130 | 130 | } |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
136 | 136 | ); |
137 | 137 | |
138 | - if ($result !== false) { |
|
138 | + if ($result !== false){ |
|
139 | 139 | //Forcing mode after file creation |
140 | 140 | $this->setPermissions($filename, $mode); |
141 | 141 | } |
142 | - } catch (\Exception $e) { |
|
142 | + }catch (\Exception $e){ |
|
143 | 143 | throw new WriteErrorException($e->getMessage(), $e->getCode(), $e); |
144 | 144 | } |
145 | 145 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function delete(string $filename) |
165 | 165 | { |
166 | - if ($this->exists($filename)) { |
|
166 | + if ($this->exists($filename)){ |
|
167 | 167 | $result = unlink($filename); |
168 | 168 | |
169 | 169 | //Wiping out changes in local file cache |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function deleteDirectory(string $directory, bool $contentOnly = false): void |
189 | 189 | { |
190 | - if (!$this->isDirectory($directory)) { |
|
190 | + if (!$this->isDirectory($directory)){ |
|
191 | 191 | throw new FilesException("Undefined or invalid directory {$directory}"); |
192 | 192 | } |
193 | 193 | |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | \RecursiveIteratorIterator::CHILD_FIRST |
197 | 197 | ); |
198 | 198 | |
199 | - foreach ($files as $file) { |
|
200 | - if ($file->isDir()) { |
|
199 | + foreach ($files as $file){ |
|
200 | + if ($file->isDir()){ |
|
201 | 201 | rmdir($file->getRealPath()); |
202 | - } else { |
|
202 | + }else{ |
|
203 | 203 | $this->delete($file->getRealPath()); |
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
207 | - if (!$contentOnly) { |
|
207 | + if (!$contentOnly){ |
|
208 | 208 | rmdir($directory); |
209 | 209 | } |
210 | 210 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function move(string $filename, string $destination): bool |
216 | 216 | { |
217 | - if (!$this->exists($filename)) { |
|
217 | + if (!$this->exists($filename)){ |
|
218 | 218 | throw new FileNotFoundException($filename); |
219 | 219 | } |
220 | 220 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function copy(string $filename, string $destination): bool |
228 | 228 | { |
229 | - if (!$this->exists($filename)) { |
|
229 | + if (!$this->exists($filename)){ |
|
230 | 230 | throw new FileNotFoundException($filename); |
231 | 231 | } |
232 | 232 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function touch(string $filename, int $mode = null): bool |
240 | 240 | { |
241 | - if (!touch($filename)) { |
|
241 | + if (!touch($filename)){ |
|
242 | 242 | return false; |
243 | 243 | } |
244 | 244 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function size(string $filename): int |
260 | 260 | { |
261 | - if (!$this->exists($filename)) { |
|
261 | + if (!$this->exists($filename)){ |
|
262 | 262 | throw new FileNotFoundException($filename); |
263 | 263 | } |
264 | 264 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function md5(string $filename): string |
280 | 280 | { |
281 | - if (!$this->exists($filename)) { |
|
281 | + if (!$this->exists($filename)){ |
|
282 | 282 | throw new FileNotFoundException($filename); |
283 | 283 | } |
284 | 284 | |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function time(string $filename): int |
292 | 292 | { |
293 | - if (!$this->exists($filename)) { |
|
293 | + if (!$this->exists($filename)){ |
|
294 | 294 | throw new FileNotFoundException($filename); |
295 | 295 | } |
296 | 296 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function getPermissions(string $filename): int |
320 | 320 | { |
321 | - if (!$this->exists($filename)) { |
|
321 | + if (!$this->exists($filename)){ |
|
322 | 322 | throw new FileNotFoundException($filename); |
323 | 323 | } |
324 | 324 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | public function setPermissions(string $filename, int $mode) |
332 | 332 | { |
333 | - if (is_dir($filename)) { |
|
333 | + if (is_dir($filename)){ |
|
334 | 334 | //Directories must always be executable (i.e. 664 for dir => 775) |
335 | 335 | $mode |= 0111; |
336 | 336 | } |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | public function getFiles(string $location, string $pattern = null): array |
345 | 345 | { |
346 | 346 | $result = []; |
347 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
348 | - if ($this->isDirectory($filename->getPathname())) { |
|
349 | - $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
347 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
348 | + if ($this->isDirectory($filename->getPathname())){ |
|
349 | + $result = array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
350 | 350 | |
351 | 351 | continue; |
352 | 352 | } |
@@ -362,13 +362,13 @@ discard block |
||
362 | 362 | */ |
363 | 363 | public function tempFilename(string $extension = '', string $location = null): string |
364 | 364 | { |
365 | - if (empty($location)) { |
|
365 | + if (empty($location)){ |
|
366 | 366 | $location = sys_get_temp_dir(); |
367 | 367 | } |
368 | 368 | |
369 | 369 | $filename = tempnam($location, 'spiral'); |
370 | 370 | |
371 | - if (!empty($extension)) { |
|
371 | + if (!empty($extension)){ |
|
372 | 372 | [$old, $filename] = [$filename, "{$filename}.{$extension}"]; |
373 | 373 | rename($old, $filename); |
374 | 374 | $this->destructFiles[] = $filename; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | $path = str_replace(['//', '\\'], '/', $path); |
386 | 386 | |
387 | 387 | //Potentially open links and ../ type directories? |
388 | - return rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
388 | + return rtrim($path, '/').($asDirectory ? '/' : ''); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
@@ -402,21 +402,21 @@ discard block |
||
402 | 402 | $path = explode('/', $path); |
403 | 403 | $relative = $path; |
404 | 404 | |
405 | - foreach ($from as $depth => $dir) { |
|
405 | + foreach ($from as $depth => $dir){ |
|
406 | 406 | //Find first non-matching dir |
407 | - if ($dir === $path[$depth]) { |
|
407 | + if ($dir === $path[$depth]){ |
|
408 | 408 | //Ignore this directory |
409 | 409 | array_shift($relative); |
410 | - } else { |
|
410 | + }else{ |
|
411 | 411 | //Get number of remaining dirs to $from |
412 | 412 | $remaining = count($from) - $depth; |
413 | - if ($remaining > 1) { |
|
413 | + if ($remaining > 1){ |
|
414 | 414 | //Add traversals up to first matching directory |
415 | 415 | $padLength = (count($relative) + $remaining - 1) * -1; |
416 | 416 | $relative = array_pad($relative, $padLength, '..'); |
417 | 417 | break; |
418 | 418 | } |
419 | - $relative[0] = './' . $relative[0]; |
|
419 | + $relative[0] = './'.$relative[0]; |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | private function filesIterator(string $location, string $pattern = null): \GlobIterator |
433 | 433 | { |
434 | 434 | $pattern = $pattern ?? '*'; |
435 | - $regexp = rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($pattern, DIRECTORY_SEPARATOR); |
|
435 | + $regexp = rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.ltrim($pattern, DIRECTORY_SEPARATOR); |
|
436 | 436 | |
437 | 437 | return new \GlobIterator($regexp); |
438 | 438 | } |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function __destruct() |
47 | 47 | { |
48 | - foreach ($this->destructFiles as $filename) { |
|
48 | + foreach ($this->destructFiles as $filename) |
|
49 | + { |
|
49 | 50 | $this->delete($filename); |
50 | 51 | } |
51 | 52 | } |
@@ -60,30 +61,36 @@ discard block |
||
60 | 61 | int $mode = null, |
61 | 62 | bool $recursivePermissions = true |
62 | 63 | ): bool { |
63 | - if (empty($mode)) { |
|
64 | + if (empty($mode)) |
|
65 | + { |
|
64 | 66 | $mode = self::DEFAULT_FILE_MODE; |
65 | 67 | } |
66 | 68 | |
67 | 69 | //Directories always executable |
68 | 70 | $mode = $mode | 0111; |
69 | - if (is_dir($directory)) { |
|
71 | + if (is_dir($directory)) |
|
72 | + { |
|
70 | 73 | //Exists :( |
71 | 74 | return $this->setPermissions($directory, $mode); |
72 | 75 | } |
73 | 76 | |
74 | - if (!$recursivePermissions) { |
|
77 | + if (!$recursivePermissions) |
|
78 | + { |
|
75 | 79 | return mkdir($directory, $mode, true); |
76 | 80 | } |
77 | 81 | |
78 | 82 | $directoryChain = [basename($directory)]; |
79 | 83 | |
80 | 84 | $baseDirectory = $directory; |
81 | - while (!is_dir($baseDirectory = dirname($baseDirectory))) { |
|
85 | + while (!is_dir($baseDirectory = dirname($baseDirectory))) |
|
86 | + { |
|
82 | 87 | $directoryChain[] = basename($baseDirectory); |
83 | 88 | } |
84 | 89 | |
85 | - foreach (array_reverse($directoryChain) as $directory) { |
|
86 | - if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) { |
|
90 | + foreach (array_reverse($directoryChain) as $directory) |
|
91 | + { |
|
92 | + if (!mkdir($baseDirectory = "{$baseDirectory}/{$directory}")) |
|
93 | + { |
|
87 | 94 | return false; |
88 | 95 | } |
89 | 96 | |
@@ -98,7 +105,8 @@ discard block |
||
98 | 105 | */ |
99 | 106 | public function read(string $filename): string |
100 | 107 | { |
101 | - if (!$this->exists($filename)) { |
|
108 | + if (!$this->exists($filename)) |
|
109 | + { |
|
102 | 110 | throw new FileNotFoundException($filename); |
103 | 111 | } |
104 | 112 | |
@@ -119,12 +127,15 @@ discard block |
||
119 | 127 | ): bool { |
120 | 128 | $mode = $mode ?? self::DEFAULT_FILE_MODE; |
121 | 129 | |
122 | - try { |
|
123 | - if ($ensureDirectory) { |
|
130 | + try |
|
131 | + { |
|
132 | + if ($ensureDirectory) |
|
133 | + { |
|
124 | 134 | $this->ensureDirectory(dirname($filename), $mode); |
125 | 135 | } |
126 | 136 | |
127 | - if ($this->exists($filename)) { |
|
137 | + if ($this->exists($filename)) |
|
138 | + { |
|
128 | 139 | //Forcing mode for existed file |
129 | 140 | $this->setPermissions($filename, $mode); |
130 | 141 | } |
@@ -135,11 +146,14 @@ discard block |
||
135 | 146 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
136 | 147 | ); |
137 | 148 | |
138 | - if ($result !== false) { |
|
149 | + if ($result !== false) |
|
150 | + { |
|
139 | 151 | //Forcing mode after file creation |
140 | 152 | $this->setPermissions($filename, $mode); |
141 | 153 | } |
142 | - } catch (\Exception $e) { |
|
154 | + } |
|
155 | + catch (\Exception $e) |
|
156 | + { |
|
143 | 157 | throw new WriteErrorException($e->getMessage(), $e->getCode(), $e); |
144 | 158 | } |
145 | 159 | |
@@ -163,7 +177,8 @@ discard block |
||
163 | 177 | */ |
164 | 178 | public function delete(string $filename) |
165 | 179 | { |
166 | - if ($this->exists($filename)) { |
|
180 | + if ($this->exists($filename)) |
|
181 | + { |
|
167 | 182 | $result = unlink($filename); |
168 | 183 | |
169 | 184 | //Wiping out changes in local file cache |
@@ -187,7 +202,8 @@ discard block |
||
187 | 202 | */ |
188 | 203 | public function deleteDirectory(string $directory, bool $contentOnly = false): void |
189 | 204 | { |
190 | - if (!$this->isDirectory($directory)) { |
|
205 | + if (!$this->isDirectory($directory)) |
|
206 | + { |
|
191 | 207 | throw new FilesException("Undefined or invalid directory {$directory}"); |
192 | 208 | } |
193 | 209 | |
@@ -196,15 +212,20 @@ discard block |
||
196 | 212 | \RecursiveIteratorIterator::CHILD_FIRST |
197 | 213 | ); |
198 | 214 | |
199 | - foreach ($files as $file) { |
|
200 | - if ($file->isDir()) { |
|
215 | + foreach ($files as $file) |
|
216 | + { |
|
217 | + if ($file->isDir()) |
|
218 | + { |
|
201 | 219 | rmdir($file->getRealPath()); |
202 | - } else { |
|
220 | + } |
|
221 | + else |
|
222 | + { |
|
203 | 223 | $this->delete($file->getRealPath()); |
204 | 224 | } |
205 | 225 | } |
206 | 226 | |
207 | - if (!$contentOnly) { |
|
227 | + if (!$contentOnly) |
|
228 | + { |
|
208 | 229 | rmdir($directory); |
209 | 230 | } |
210 | 231 | } |
@@ -214,7 +235,8 @@ discard block |
||
214 | 235 | */ |
215 | 236 | public function move(string $filename, string $destination): bool |
216 | 237 | { |
217 | - if (!$this->exists($filename)) { |
|
238 | + if (!$this->exists($filename)) |
|
239 | + { |
|
218 | 240 | throw new FileNotFoundException($filename); |
219 | 241 | } |
220 | 242 | |
@@ -226,7 +248,8 @@ discard block |
||
226 | 248 | */ |
227 | 249 | public function copy(string $filename, string $destination): bool |
228 | 250 | { |
229 | - if (!$this->exists($filename)) { |
|
251 | + if (!$this->exists($filename)) |
|
252 | + { |
|
230 | 253 | throw new FileNotFoundException($filename); |
231 | 254 | } |
232 | 255 | |
@@ -238,7 +261,8 @@ discard block |
||
238 | 261 | */ |
239 | 262 | public function touch(string $filename, int $mode = null): bool |
240 | 263 | { |
241 | - if (!touch($filename)) { |
|
264 | + if (!touch($filename)) |
|
265 | + { |
|
242 | 266 | return false; |
243 | 267 | } |
244 | 268 | |
@@ -258,7 +282,8 @@ discard block |
||
258 | 282 | */ |
259 | 283 | public function size(string $filename): int |
260 | 284 | { |
261 | - if (!$this->exists($filename)) { |
|
285 | + if (!$this->exists($filename)) |
|
286 | + { |
|
262 | 287 | throw new FileNotFoundException($filename); |
263 | 288 | } |
264 | 289 | |
@@ -278,7 +303,8 @@ discard block |
||
278 | 303 | */ |
279 | 304 | public function md5(string $filename): string |
280 | 305 | { |
281 | - if (!$this->exists($filename)) { |
|
306 | + if (!$this->exists($filename)) |
|
307 | + { |
|
282 | 308 | throw new FileNotFoundException($filename); |
283 | 309 | } |
284 | 310 | |
@@ -290,7 +316,8 @@ discard block |
||
290 | 316 | */ |
291 | 317 | public function time(string $filename): int |
292 | 318 | { |
293 | - if (!$this->exists($filename)) { |
|
319 | + if (!$this->exists($filename)) |
|
320 | + { |
|
294 | 321 | throw new FileNotFoundException($filename); |
295 | 322 | } |
296 | 323 | |
@@ -318,7 +345,8 @@ discard block |
||
318 | 345 | */ |
319 | 346 | public function getPermissions(string $filename): int |
320 | 347 | { |
321 | - if (!$this->exists($filename)) { |
|
348 | + if (!$this->exists($filename)) |
|
349 | + { |
|
322 | 350 | throw new FileNotFoundException($filename); |
323 | 351 | } |
324 | 352 | |
@@ -330,7 +358,8 @@ discard block |
||
330 | 358 | */ |
331 | 359 | public function setPermissions(string $filename, int $mode) |
332 | 360 | { |
333 | - if (is_dir($filename)) { |
|
361 | + if (is_dir($filename)) |
|
362 | + { |
|
334 | 363 | //Directories must always be executable (i.e. 664 for dir => 775) |
335 | 364 | $mode |= 0111; |
336 | 365 | } |
@@ -344,8 +373,10 @@ discard block |
||
344 | 373 | public function getFiles(string $location, string $pattern = null): array |
345 | 374 | { |
346 | 375 | $result = []; |
347 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
348 | - if ($this->isDirectory($filename->getPathname())) { |
|
376 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
377 | + { |
|
378 | + if ($this->isDirectory($filename->getPathname())) |
|
379 | + { |
|
349 | 380 | $result = array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
350 | 381 | |
351 | 382 | continue; |
@@ -362,13 +393,15 @@ discard block |
||
362 | 393 | */ |
363 | 394 | public function tempFilename(string $extension = '', string $location = null): string |
364 | 395 | { |
365 | - if (empty($location)) { |
|
396 | + if (empty($location)) |
|
397 | + { |
|
366 | 398 | $location = sys_get_temp_dir(); |
367 | 399 | } |
368 | 400 | |
369 | 401 | $filename = tempnam($location, 'spiral'); |
370 | 402 | |
371 | - if (!empty($extension)) { |
|
403 | + if (!empty($extension)) |
|
404 | + { |
|
372 | 405 | [$old, $filename] = [$filename, "{$filename}.{$extension}"]; |
373 | 406 | rename($old, $filename); |
374 | 407 | $this->destructFiles[] = $filename; |
@@ -402,15 +435,20 @@ discard block |
||
402 | 435 | $path = explode('/', $path); |
403 | 436 | $relative = $path; |
404 | 437 | |
405 | - foreach ($from as $depth => $dir) { |
|
438 | + foreach ($from as $depth => $dir) |
|
439 | + { |
|
406 | 440 | //Find first non-matching dir |
407 | - if ($dir === $path[$depth]) { |
|
441 | + if ($dir === $path[$depth]) |
|
442 | + { |
|
408 | 443 | //Ignore this directory |
409 | 444 | array_shift($relative); |
410 | - } else { |
|
445 | + } |
|
446 | + else |
|
447 | + { |
|
411 | 448 | //Get number of remaining dirs to $from |
412 | 449 | $remaining = count($from) - $depth; |
413 | - if ($remaining > 1) { |
|
450 | + if ($remaining > 1) |
|
451 | + { |
|
414 | 452 | //Add traversals up to first matching directory |
415 | 453 | $padLength = (count($relative) + $remaining - 1) * -1; |
416 | 454 | $relative = array_pad($relative, $padLength, '..'); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null){ |
|
51 | 51 | $lexer = new Lexer\Emulative([ |
52 | 52 | 'usedAttributes' => [ |
53 | 53 | 'comments', |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | bool $useTypedProperties = false, |
87 | 87 | bool $noPhpDoc = false |
88 | 88 | ): string { |
89 | - if (empty($node->dependencies)) { |
|
90 | - if ($removeTrait) { |
|
89 | + if (empty($node->dependencies)){ |
|
90 | + if ($removeTrait){ |
|
91 | 91 | $tr = new NodeTraverser(); |
92 | 92 | $tr->addVisitor(new RemoveUse()); |
93 | 93 | $tr->addVisitor(new RemoveTrait()); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $tr = new NodeTraverser(); |
102 | 102 | $tr->addVisitor(new AddUse($node)); |
103 | 103 | |
104 | - if ($removeTrait) { |
|
104 | + if ($removeTrait){ |
|
105 | 105 | $tr->addVisitor(new RemoveUse()); |
106 | 106 | $tr->addVisitor(new RemoveTrait()); |
107 | 107 | } |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(Lexer $lexer = null, PrettyPrinterAbstract $printer = null) |
49 | 49 | { |
50 | - if ($lexer === null) { |
|
50 | + if ($lexer === null) |
|
51 | + { |
|
51 | 52 | $lexer = new Lexer\Emulative([ |
52 | 53 | 'usedAttributes' => [ |
53 | 54 | 'comments', |
@@ -86,8 +87,10 @@ discard block |
||
86 | 87 | bool $useTypedProperties = false, |
87 | 88 | bool $noPhpDoc = false |
88 | 89 | ): string { |
89 | - if (empty($node->dependencies)) { |
|
90 | - if ($removeTrait) { |
|
90 | + if (empty($node->dependencies)) |
|
91 | + { |
|
92 | + if ($removeTrait) |
|
93 | + { |
|
91 | 94 | $tr = new NodeTraverser(); |
92 | 95 | $tr->addVisitor(new RemoveUse()); |
93 | 96 | $tr->addVisitor(new RemoveTrait()); |
@@ -101,7 +104,8 @@ discard block |
||
101 | 104 | $tr = new NodeTraverser(); |
102 | 105 | $tr->addVisitor(new AddUse($node)); |
103 | 106 | |
104 | - if ($removeTrait) { |
|
107 | + if ($removeTrait) |
|
108 | + { |
|
105 | 109 | $tr->addVisitor(new RemoveUse()); |
106 | 110 | $tr->addVisitor(new RemoveTrait()); |
107 | 111 | } |
@@ -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 |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $name = $name ?? $this->default; |
79 | 79 | |
80 | - if (!isset($this->buckets[$name])) { |
|
80 | + if (!isset($this->buckets[$name])){ |
|
81 | 81 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
82 | 82 | } |
83 | 83 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function add(string $name, BucketInterface $storage, bool $overwrite = false): void |
101 | 101 | { |
102 | - if ($overwrite === false && isset($this->buckets[$name])) { |
|
102 | + if ($overwrite === false && isset($this->buckets[$name])){ |
|
103 | 103 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
104 | 104 | } |
105 | 105 | |
@@ -133,22 +133,22 @@ discard block |
||
133 | 133 | $uri = $this->uriToString($uri); |
134 | 134 | $result = \parse_url($uri); |
135 | 135 | |
136 | - if ($result === false) { |
|
136 | + if ($result === false){ |
|
137 | 137 | $message = 'URI argument must be a valid URI in "[STORAGE]://[PATH_TO_FILE]" format, but `%s` given'; |
138 | 138 | throw new InvalidArgumentException(\sprintf($message, $uri)); |
139 | 139 | } |
140 | 140 | |
141 | - if (!isset($result['scheme'])) { |
|
141 | + if (!isset($result['scheme'])){ |
|
142 | 142 | $result['scheme'] = $withScheme ? $this->default : null; |
143 | 143 | } |
144 | 144 | |
145 | - if (!isset($result['host'])) { |
|
145 | + if (!isset($result['host'])){ |
|
146 | 146 | $result['host'] = ''; |
147 | 147 | } |
148 | 148 | |
149 | 149 | return [ |
150 | 150 | $result['scheme'] ?? null, |
151 | - $result['host'] . \rtrim($result['path'] ?? '', '/'), |
|
151 | + $result['host'].\rtrim($result['path'] ?? '', '/'), |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | private function uriToString($uri): string |
161 | 161 | { |
162 | - switch (true) { |
|
162 | + switch (true){ |
|
163 | 163 | case $uri instanceof UriInterface: |
164 | 164 | case $uri instanceof \Stringable: |
165 | 165 | case \is_object($uri) && \method_exists($uri, '__toString'): |
@@ -77,7 +77,8 @@ discard block |
||
77 | 77 | { |
78 | 78 | $name = $name ?? $this->default; |
79 | 79 | |
80 | - if (!isset($this->buckets[$name])) { |
|
80 | + if (!isset($this->buckets[$name])) |
|
81 | + { |
|
81 | 82 | throw new InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
82 | 83 | } |
83 | 84 | |
@@ -99,7 +100,8 @@ discard block |
||
99 | 100 | */ |
100 | 101 | public function add(string $name, BucketInterface $storage, bool $overwrite = false): void |
101 | 102 | { |
102 | - if ($overwrite === false && isset($this->buckets[$name])) { |
|
103 | + if ($overwrite === false && isset($this->buckets[$name])) |
|
104 | + { |
|
103 | 105 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
104 | 106 | } |
105 | 107 | |
@@ -133,16 +135,19 @@ discard block |
||
133 | 135 | $uri = $this->uriToString($uri); |
134 | 136 | $result = \parse_url($uri); |
135 | 137 | |
136 | - if ($result === false) { |
|
138 | + if ($result === false) |
|
139 | + { |
|
137 | 140 | $message = 'URI argument must be a valid URI in "[STORAGE]://[PATH_TO_FILE]" format, but `%s` given'; |
138 | 141 | throw new InvalidArgumentException(\sprintf($message, $uri)); |
139 | 142 | } |
140 | 143 | |
141 | - if (!isset($result['scheme'])) { |
|
144 | + if (!isset($result['scheme'])) |
|
145 | + { |
|
142 | 146 | $result['scheme'] = $withScheme ? $this->default : null; |
143 | 147 | } |
144 | 148 | |
145 | - if (!isset($result['host'])) { |
|
149 | + if (!isset($result['host'])) |
|
150 | + { |
|
146 | 151 | $result['host'] = ''; |
147 | 152 | } |
148 | 153 | |
@@ -159,7 +164,8 @@ discard block |
||
159 | 164 | */ |
160 | 165 | private function uriToString($uri): string |
161 | 166 | { |
162 | - switch (true) { |
|
167 | + switch (true) |
|
168 | + { |
|
163 | 169 | case $uri instanceof UriInterface: |
164 | 170 | case $uri instanceof \Stringable: |
165 | 171 | case \is_object($uri) && \method_exists($uri, '__toString'): |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | { |
66 | 66 | $name = $name ?? $this->default; |
67 | 67 | |
68 | - if (!isset($this->resolvers[$name])) { |
|
68 | + if (!isset($this->resolvers[$name])){ |
|
69 | 69 | throw new \InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
70 | 70 | } |
71 | 71 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
79 | 79 | { |
80 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
80 | + if ($overwrite === false && isset($this->resolvers[$name])){ |
|
81 | 81 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
82 | 82 | } |
83 | 83 |
@@ -65,7 +65,8 @@ discard block |
||
65 | 65 | { |
66 | 66 | $name = $name ?? $this->default; |
67 | 67 | |
68 | - if (!isset($this->resolvers[$name])) { |
|
68 | + if (!isset($this->resolvers[$name])) |
|
69 | + { |
|
69 | 70 | throw new \InvalidArgumentException(\sprintf(self::ERROR_NOT_FOUND, $name)); |
70 | 71 | } |
71 | 72 | |
@@ -77,7 +78,8 @@ discard block |
||
77 | 78 | */ |
78 | 79 | public function add(string $name, UriResolverInterface $resolver, bool $overwrite = false): void |
79 | 80 | { |
80 | - if ($overwrite === false && isset($this->resolvers[$name])) { |
|
81 | + if ($overwrite === false && isset($this->resolvers[$name])) |
|
82 | + { |
|
81 | 83 | throw new \InvalidArgumentException(\sprintf(self::ERROR_REDEFINITION, $name)); |
82 | 84 | } |
83 | 85 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | public function __construct(array $visitors = []) |
30 | 30 | { |
31 | - foreach ($visitors as $visitor) { |
|
31 | + foreach ($visitors as $visitor){ |
|
32 | 32 | $this->addVisitor($visitor); |
33 | 33 | } |
34 | 34 | } |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | |
44 | 44 | public function removeVisitor(VisitorInterface $visitor): void |
45 | 45 | { |
46 | - foreach ($this->visitors as $index => $added) { |
|
47 | - if ($added === $visitor) { |
|
46 | + foreach ($this->visitors as $index => $added){ |
|
47 | + if ($added === $visitor){ |
|
48 | 48 | unset($this->visitors[$index]); |
49 | 49 | break; |
50 | 50 | } |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | $context = $context ?? new VisitorContext(); |
64 | 64 | |
65 | 65 | $ctx = clone $context; |
66 | - foreach ($nodes as $index => $node) { |
|
67 | - if ($this->stopTraversal) { |
|
66 | + foreach ($nodes as $index => $node){ |
|
67 | + if ($this->stopTraversal){ |
|
68 | 68 | break; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $traverseChildren = true; |
72 | 72 | $breakVisitorID = null; |
73 | 73 | |
74 | - if ($node instanceof NodeInterface) { |
|
74 | + if ($node instanceof NodeInterface){ |
|
75 | 75 | $ctx = $context->withNode($node); |
76 | 76 | } |
77 | 77 | |
78 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
78 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
79 | 79 | $result = $visitor->enterNode($node, $ctx); |
80 | 80 | |
81 | - switch (true) { |
|
81 | + switch (true){ |
|
82 | 82 | case $result === null: |
83 | 83 | break; |
84 | 84 | |
@@ -102,23 +102,23 @@ discard block |
||
102 | 102 | |
103 | 103 | default: |
104 | 104 | throw new \LogicException( |
105 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
105 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | 110 | // sub nodes |
111 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
111 | + if ($traverseChildren && $node instanceof NodeInterface){ |
|
112 | 112 | $nodes[$index] = $this->traverseNode($node, $ctx); |
113 | - if ($this->stopTraversal) { |
|
113 | + if ($this->stopTraversal){ |
|
114 | 114 | break; |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
118 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
119 | 119 | $result = $visitor->leaveNode($node, $ctx); |
120 | 120 | |
121 | - switch (true) { |
|
121 | + switch (true){ |
|
122 | 122 | case $result === null: |
123 | 123 | break; |
124 | 124 | |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | |
137 | 137 | default: |
138 | 138 | throw new \LogicException( |
139 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
139 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
140 | 140 | ); |
141 | 141 | } |
142 | 142 | |
143 | - if ($breakVisitorID === $visitorID) { |
|
143 | + if ($breakVisitorID === $visitorID){ |
|
144 | 144 | break; |
145 | 145 | } |
146 | 146 | } |
@@ -155,18 +155,18 @@ discard block |
||
155 | 155 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
156 | 156 | { |
157 | 157 | $ctx = clone $context; |
158 | - foreach ($node as $name => $_) { |
|
158 | + foreach ($node as $name => $_){ |
|
159 | 159 | $child = &$node->$name; |
160 | - if (is_array($child)) { |
|
160 | + if (is_array($child)){ |
|
161 | 161 | $child = $this->traverse($child, $ctx); |
162 | - if ($this->stopTraversal) { |
|
162 | + if ($this->stopTraversal){ |
|
163 | 163 | break; |
164 | 164 | } |
165 | 165 | |
166 | 166 | continue; |
167 | 167 | } |
168 | 168 | |
169 | - if (!$child instanceof NodeInterface) { |
|
169 | + if (!$child instanceof NodeInterface){ |
|
170 | 170 | continue; |
171 | 171 | } |
172 | 172 | |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | $traverseChildren = true; |
176 | 176 | $breakVisitorID = null; |
177 | 177 | |
178 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
178 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
179 | 179 | $result = $visitor->enterNode($child, $ctx); |
180 | - switch (true) { |
|
180 | + switch (true){ |
|
181 | 181 | case $result === null: |
182 | 182 | break; |
183 | 183 | |
@@ -200,22 +200,22 @@ discard block |
||
200 | 200 | |
201 | 201 | default: |
202 | 202 | throw new \LogicException( |
203 | - 'enterNode() returned invalid value of type ' . gettype($result) |
|
203 | + 'enterNode() returned invalid value of type '.gettype($result) |
|
204 | 204 | ); |
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
208 | - if ($traverseChildren) { |
|
208 | + if ($traverseChildren){ |
|
209 | 209 | $child = $this->traverseNode($child, $ctx); |
210 | - if ($this->stopTraversal) { |
|
210 | + if ($this->stopTraversal){ |
|
211 | 211 | break; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
215 | + foreach ($this->visitors as $visitorID => $visitor){ |
|
216 | 216 | $result = $visitor->leaveNode($child, $ctx); |
217 | 217 | |
218 | - switch (true) { |
|
218 | + switch (true){ |
|
219 | 219 | case $result === null: |
220 | 220 | break; |
221 | 221 | |
@@ -229,11 +229,11 @@ discard block |
||
229 | 229 | |
230 | 230 | default: |
231 | 231 | throw new \LogicException( |
232 | - 'leaveNode() returned invalid value of type ' . gettype($result) |
|
232 | + 'leaveNode() returned invalid value of type '.gettype($result) |
|
233 | 233 | ); |
234 | 234 | } |
235 | 235 | |
236 | - if ($breakVisitorID === $visitorID) { |
|
236 | + if ($breakVisitorID === $visitorID){ |
|
237 | 237 | break; |
238 | 238 | } |
239 | 239 | } |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | |
29 | 29 | public function __construct(array $visitors = []) |
30 | 30 | { |
31 | - foreach ($visitors as $visitor) { |
|
31 | + foreach ($visitors as $visitor) |
|
32 | + { |
|
32 | 33 | $this->addVisitor($visitor); |
33 | 34 | } |
34 | 35 | } |
@@ -43,8 +44,10 @@ discard block |
||
43 | 44 | |
44 | 45 | public function removeVisitor(VisitorInterface $visitor): void |
45 | 46 | { |
46 | - foreach ($this->visitors as $index => $added) { |
|
47 | - if ($added === $visitor) { |
|
47 | + foreach ($this->visitors as $index => $added) |
|
48 | + { |
|
49 | + if ($added === $visitor) |
|
50 | + { |
|
48 | 51 | unset($this->visitors[$index]); |
49 | 52 | break; |
50 | 53 | } |
@@ -63,22 +66,27 @@ discard block |
||
63 | 66 | $context = $context ?? new VisitorContext(); |
64 | 67 | |
65 | 68 | $ctx = clone $context; |
66 | - foreach ($nodes as $index => $node) { |
|
67 | - if ($this->stopTraversal) { |
|
69 | + foreach ($nodes as $index => $node) |
|
70 | + { |
|
71 | + if ($this->stopTraversal) |
|
72 | + { |
|
68 | 73 | break; |
69 | 74 | } |
70 | 75 | |
71 | 76 | $traverseChildren = true; |
72 | 77 | $breakVisitorID = null; |
73 | 78 | |
74 | - if ($node instanceof NodeInterface) { |
|
79 | + if ($node instanceof NodeInterface) |
|
80 | + { |
|
75 | 81 | $ctx = $context->withNode($node); |
76 | 82 | } |
77 | 83 | |
78 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
84 | + foreach ($this->visitors as $visitorID => $visitor) |
|
85 | + { |
|
79 | 86 | $result = $visitor->enterNode($node, $ctx); |
80 | 87 | |
81 | - switch (true) { |
|
88 | + switch (true) |
|
89 | + { |
|
82 | 90 | case $result === null: |
83 | 91 | break; |
84 | 92 | |
@@ -108,17 +116,21 @@ discard block |
||
108 | 116 | } |
109 | 117 | |
110 | 118 | // sub nodes |
111 | - if ($traverseChildren && $node instanceof NodeInterface) { |
|
119 | + if ($traverseChildren && $node instanceof NodeInterface) |
|
120 | + { |
|
112 | 121 | $nodes[$index] = $this->traverseNode($node, $ctx); |
113 | - if ($this->stopTraversal) { |
|
122 | + if ($this->stopTraversal) |
|
123 | + { |
|
114 | 124 | break; |
115 | 125 | } |
116 | 126 | } |
117 | 127 | |
118 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
128 | + foreach ($this->visitors as $visitorID => $visitor) |
|
129 | + { |
|
119 | 130 | $result = $visitor->leaveNode($node, $ctx); |
120 | 131 | |
121 | - switch (true) { |
|
132 | + switch (true) |
|
133 | + { |
|
122 | 134 | case $result === null: |
123 | 135 | break; |
124 | 136 | |
@@ -140,7 +152,8 @@ discard block |
||
140 | 152 | ); |
141 | 153 | } |
142 | 154 | |
143 | - if ($breakVisitorID === $visitorID) { |
|
155 | + if ($breakVisitorID === $visitorID) |
|
156 | + { |
|
144 | 157 | break; |
145 | 158 | } |
146 | 159 | } |
@@ -155,18 +168,22 @@ discard block |
||
155 | 168 | private function traverseNode(NodeInterface $node, VisitorContext $context): NodeInterface |
156 | 169 | { |
157 | 170 | $ctx = clone $context; |
158 | - foreach ($node as $name => $_) { |
|
171 | + foreach ($node as $name => $_) |
|
172 | + { |
|
159 | 173 | $child = &$node->$name; |
160 | - if (is_array($child)) { |
|
174 | + if (is_array($child)) |
|
175 | + { |
|
161 | 176 | $child = $this->traverse($child, $ctx); |
162 | - if ($this->stopTraversal) { |
|
177 | + if ($this->stopTraversal) |
|
178 | + { |
|
163 | 179 | break; |
164 | 180 | } |
165 | 181 | |
166 | 182 | continue; |
167 | 183 | } |
168 | 184 | |
169 | - if (!$child instanceof NodeInterface) { |
|
185 | + if (!$child instanceof NodeInterface) |
|
186 | + { |
|
170 | 187 | continue; |
171 | 188 | } |
172 | 189 | |
@@ -175,9 +192,11 @@ discard block |
||
175 | 192 | $traverseChildren = true; |
176 | 193 | $breakVisitorID = null; |
177 | 194 | |
178 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
195 | + foreach ($this->visitors as $visitorID => $visitor) |
|
196 | + { |
|
179 | 197 | $result = $visitor->enterNode($child, $ctx); |
180 | - switch (true) { |
|
198 | + switch (true) |
|
199 | + { |
|
181 | 200 | case $result === null: |
182 | 201 | break; |
183 | 202 | |
@@ -205,17 +224,21 @@ discard block |
||
205 | 224 | } |
206 | 225 | } |
207 | 226 | |
208 | - if ($traverseChildren) { |
|
227 | + if ($traverseChildren) |
|
228 | + { |
|
209 | 229 | $child = $this->traverseNode($child, $ctx); |
210 | - if ($this->stopTraversal) { |
|
230 | + if ($this->stopTraversal) |
|
231 | + { |
|
211 | 232 | break; |
212 | 233 | } |
213 | 234 | } |
214 | 235 | |
215 | - foreach ($this->visitors as $visitorID => $visitor) { |
|
236 | + foreach ($this->visitors as $visitorID => $visitor) |
|
237 | + { |
|
216 | 238 | $result = $visitor->leaveNode($child, $ctx); |
217 | 239 | |
218 | - switch (true) { |
|
240 | + switch (true) |
|
241 | + { |
|
219 | 242 | case $result === null: |
220 | 243 | break; |
221 | 244 | |
@@ -233,7 +256,8 @@ discard block |
||
233 | 256 | ); |
234 | 257 | } |
235 | 258 | |
236 | - if ($breakVisitorID === $visitorID) { |
|
259 | + if ($breakVisitorID === $visitorID) |
|
260 | + { |
|
237 | 261 | break; |
238 | 262 | } |
239 | 263 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | public function __construct( |
33 | 33 | DirectiveRendererInterface $directiveRenderer = null, |
34 | 34 | string $defaultFilter = self::DEFAULT_FILTER |
35 | - ) { |
|
35 | + ){ |
|
36 | 36 | $this->directiveRenderer = $directiveRenderer; |
37 | 37 | $this->defaultFilter = $defaultFilter; |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
44 | 44 | { |
45 | - switch (true) { |
|
45 | + switch (true){ |
|
46 | 46 | case $node instanceof Output: |
47 | 47 | $this->output($result, $node); |
48 | 48 | return true; |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | private function directive(Compiler\Result $source, Directive $directive): void |
62 | 62 | { |
63 | - if ($this->directiveRenderer !== null) { |
|
63 | + if ($this->directiveRenderer !== null){ |
|
64 | 64 | $result = $this->directiveRenderer->render($directive); |
65 | - if ($result !== null) { |
|
65 | + if ($result !== null){ |
|
66 | 66 | $source->push($result, $directive->getContext()); |
67 | 67 | return; |
68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | private function output(Compiler\Result $source, Output $output): void |
78 | 78 | { |
79 | - if ($output->rawOutput) { |
|
79 | + if ($output->rawOutput){ |
|
80 | 80 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
81 | 81 | return; |
82 | 82 | } |
@@ -42,7 +42,8 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function render(Compiler $compiler, Compiler\Result $result, NodeInterface $node): bool |
44 | 44 | { |
45 | - switch (true) { |
|
45 | + switch (true) |
|
46 | + { |
|
46 | 47 | case $node instanceof Output: |
47 | 48 | $this->output($result, $node); |
48 | 49 | return true; |
@@ -60,9 +61,11 @@ discard block |
||
60 | 61 | */ |
61 | 62 | private function directive(Compiler\Result $source, Directive $directive): void |
62 | 63 | { |
63 | - if ($this->directiveRenderer !== null) { |
|
64 | + if ($this->directiveRenderer !== null) |
|
65 | + { |
|
64 | 66 | $result = $this->directiveRenderer->render($directive); |
65 | - if ($result !== null) { |
|
67 | + if ($result !== null) |
|
68 | + { |
|
66 | 69 | $source->push($result, $directive->getContext()); |
67 | 70 | return; |
68 | 71 | } |
@@ -76,7 +79,8 @@ discard block |
||
76 | 79 | |
77 | 80 | private function output(Compiler\Result $source, Output $output): void |
78 | 81 | { |
79 | - if ($output->rawOutput) { |
|
82 | + if ($output->rawOutput) |
|
83 | + { |
|
80 | 84 | $source->push(sprintf('<?php echo %s; ?>', trim($output->body)), $output->getContext()); |
81 | 85 | return; |
82 | 86 | } |