@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function hasField(string $name): bool |
81 | 81 | { |
82 | - if (!array_key_exists($name, $this->fields)) { |
|
82 | + if (!array_key_exists($name, $this->fields)){ |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function setField(string $name, $value, bool $filter = true): void |
97 | 97 | { |
98 | - if ($value instanceof ValueInterface) { |
|
98 | + if ($value instanceof ValueInterface){ |
|
99 | 99 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
100 | 100 | $this->fields[$name] = clone $value; |
101 | 101 | |
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
105 | + if (!$filter || (is_null($value) && $this->isNullable($name))){ |
|
106 | 106 | //Bypassing all filters |
107 | 107 | $this->fields[$name] = $value; |
108 | 108 | |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | //Checking if field have accessor |
113 | 113 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
114 | 114 | |
115 | - if ($accessor !== null) { |
|
115 | + if ($accessor !== null){ |
|
116 | 116 | //Setting value thought associated accessor |
117 | 117 | $this->thoughValue($accessor, $name, $value); |
118 | - } else { |
|
118 | + }else{ |
|
119 | 119 | //Setting value thought setter filter (if any) |
120 | 120 | $this->setMutated($name, $value); |
121 | 121 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | { |
133 | 133 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
134 | 134 | |
135 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
135 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))){ |
|
136 | 136 | //Direct access to value when value is accessor or null and declared as nullable |
137 | 137 | return $value; |
138 | 138 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | //Checking if field have accessor (decorator) |
141 | 141 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
142 | 142 | |
143 | - if (!empty($accessor)) { |
|
143 | + if (!empty($accessor)){ |
|
144 | 144 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
145 | 145 | } |
146 | 146 | |
@@ -163,15 +163,15 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function setFields($fields = [], bool $all = false) |
165 | 165 | { |
166 | - if (!is_array($fields) && !$fields instanceof \Traversable) { |
|
166 | + if (!is_array($fields) && !$fields instanceof \Traversable){ |
|
167 | 167 | return $this; |
168 | 168 | } |
169 | 169 | |
170 | - foreach ($fields as $name => $value) { |
|
171 | - if ($all || $this->isFillable($name)) { |
|
172 | - try { |
|
170 | + foreach ($fields as $name => $value){ |
|
171 | + if ($all || $this->isFillable($name)){ |
|
172 | + try{ |
|
173 | 173 | $this->setField($name, $value, true); |
174 | - } catch (AccessExceptionInterface $e) { |
|
174 | + }catch (AccessExceptionInterface $e){ |
|
175 | 175 | //We are suppressing field setting exceptions |
176 | 176 | } |
177 | 177 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | public function getFields(bool $filter = true): array |
193 | 193 | { |
194 | 194 | $result = []; |
195 | - foreach ($this->fields as $name => $_) { |
|
195 | + foreach ($this->fields as $name => $_){ |
|
196 | 196 | $result[$name] = $this->getField($name, null, $filter); |
197 | 197 | } |
198 | 198 | |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | public function getValue(): array |
260 | 260 | { |
261 | 261 | $result = []; |
262 | - foreach ($this->fields as $field => $value) { |
|
263 | - if ($value instanceof ValueInterface) { |
|
262 | + foreach ($this->fields as $field => $value){ |
|
263 | + if ($value instanceof ValueInterface){ |
|
264 | 264 | $result[$field] = $value->getValue(); |
265 | - } else { |
|
265 | + }else{ |
|
266 | 266 | $result[$field] = $value; |
267 | 267 | } |
268 | 268 | } |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | $value, |
356 | 356 | array $context = [] |
357 | 357 | ): ValueInterface { |
358 | - if (!is_string($type) || !class_exists($type)) { |
|
358 | + if (!is_string($type) || !class_exists($type)){ |
|
359 | 359 | throw new EntityException( |
360 | - "Unable to create accessor for field `{$name}` in " . static::class |
|
360 | + "Unable to create accessor for field `{$name}` in ".static::class |
|
361 | 361 | ); |
362 | 362 | } |
363 | 363 | |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | { |
378 | 378 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
379 | 379 | |
380 | - if ($filter && !empty($getter)) { |
|
381 | - try { |
|
380 | + if ($filter && !empty($getter)){ |
|
381 | + try{ |
|
382 | 382 | return call_user_func($getter, $value); |
383 | - } catch (\Exception $e) { |
|
383 | + }catch (\Exception $e){ |
|
384 | 384 | //Trying to filter null value, every filter must support it |
385 | 385 | return call_user_func($getter, null); |
386 | 386 | } |
@@ -399,13 +399,13 @@ discard block |
||
399 | 399 | { |
400 | 400 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
401 | 401 | |
402 | - if (!empty($setter)) { |
|
403 | - try { |
|
402 | + if (!empty($setter)){ |
|
403 | + try{ |
|
404 | 404 | $this->fields[$name] = call_user_func($setter, $value); |
405 | - } catch (\Exception $e) { |
|
405 | + }catch (\Exception $e){ |
|
406 | 406 | //Exceptional situation, we are choosing to keep original field value |
407 | 407 | } |
408 | - } else { |
|
408 | + }else{ |
|
409 | 409 | $this->fields[$name] = $value; |
410 | 410 | } |
411 | 411 | } |
@@ -419,13 +419,13 @@ discard block |
||
419 | 419 | */ |
420 | 420 | private function thoughValue($type, string $name, $value): void |
421 | 421 | { |
422 | - if (array_key_exists($name, $this->fields)) { |
|
422 | + if (array_key_exists($name, $this->fields)){ |
|
423 | 423 | $field = $this->fields[$name]; |
424 | - } else { |
|
424 | + }else{ |
|
425 | 425 | $field = null; |
426 | 426 | } |
427 | 427 | |
428 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
428 | + if (empty($field) || !($field instanceof ValueInterface)){ |
|
429 | 429 | //New field representation |
430 | 430 | $field = $this->createValue($type, $name, $value); |
431 | 431 |
@@ -79,7 +79,8 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function hasField(string $name): bool |
81 | 81 | { |
82 | - if (!array_key_exists($name, $this->fields)) { |
|
82 | + if (!array_key_exists($name, $this->fields)) |
|
83 | + { |
|
83 | 84 | return false; |
84 | 85 | } |
85 | 86 | |
@@ -95,14 +96,16 @@ discard block |
||
95 | 96 | */ |
96 | 97 | public function setField(string $name, $value, bool $filter = true): void |
97 | 98 | { |
98 | - if ($value instanceof ValueInterface) { |
|
99 | + if ($value instanceof ValueInterface) |
|
100 | + { |
|
99 | 101 | //In case of non scalar values filters must be bypassed (check accessor compatibility?) |
100 | 102 | $this->fields[$name] = clone $value; |
101 | 103 | |
102 | 104 | return; |
103 | 105 | } |
104 | 106 | |
105 | - if (!$filter || (is_null($value) && $this->isNullable($name))) { |
|
107 | + if (!$filter || (is_null($value) && $this->isNullable($name))) |
|
108 | + { |
|
106 | 109 | //Bypassing all filters |
107 | 110 | $this->fields[$name] = $value; |
108 | 111 | |
@@ -112,10 +115,13 @@ discard block |
||
112 | 115 | //Checking if field have accessor |
113 | 116 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
114 | 117 | |
115 | - if ($accessor !== null) { |
|
118 | + if ($accessor !== null) |
|
119 | + { |
|
116 | 120 | //Setting value thought associated accessor |
117 | 121 | $this->thoughValue($accessor, $name, $value); |
118 | - } else { |
|
122 | + } |
|
123 | + else |
|
124 | + { |
|
119 | 125 | //Setting value thought setter filter (if any) |
120 | 126 | $this->setMutated($name, $value); |
121 | 127 | } |
@@ -132,7 +138,8 @@ discard block |
||
132 | 138 | { |
133 | 139 | $value = $this->hasField($name) ? $this->fields[$name] : $default; |
134 | 140 | |
135 | - if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) { |
|
141 | + if ($value instanceof ValueInterface || (is_null($value) && $this->isNullable($name))) |
|
142 | + { |
|
136 | 143 | //Direct access to value when value is accessor or null and declared as nullable |
137 | 144 | return $value; |
138 | 145 | } |
@@ -140,7 +147,8 @@ discard block |
||
140 | 147 | //Checking if field have accessor (decorator) |
141 | 148 | $accessor = $this->getMutator($name, ModelSchema::MUTATOR_ACCESSOR); |
142 | 149 | |
143 | - if (!empty($accessor)) { |
|
150 | + if (!empty($accessor)) |
|
151 | + { |
|
144 | 152 | return $this->fields[$name] = $this->createValue($accessor, $name, $value); |
145 | 153 | } |
146 | 154 | |
@@ -163,15 +171,21 @@ discard block |
||
163 | 171 | */ |
164 | 172 | public function setFields($fields = [], bool $all = false) |
165 | 173 | { |
166 | - if (!is_array($fields) && !$fields instanceof \Traversable) { |
|
174 | + if (!is_array($fields) && !$fields instanceof \Traversable) |
|
175 | + { |
|
167 | 176 | return $this; |
168 | 177 | } |
169 | 178 | |
170 | - foreach ($fields as $name => $value) { |
|
171 | - if ($all || $this->isFillable($name)) { |
|
172 | - try { |
|
179 | + foreach ($fields as $name => $value) |
|
180 | + { |
|
181 | + if ($all || $this->isFillable($name)) |
|
182 | + { |
|
183 | + try |
|
184 | + { |
|
173 | 185 | $this->setField($name, $value, true); |
174 | - } catch (AccessExceptionInterface $e) { |
|
186 | + } |
|
187 | + catch (AccessExceptionInterface $e) |
|
188 | + { |
|
175 | 189 | //We are suppressing field setting exceptions |
176 | 190 | } |
177 | 191 | } |
@@ -192,7 +206,8 @@ discard block |
||
192 | 206 | public function getFields(bool $filter = true): array |
193 | 207 | { |
194 | 208 | $result = []; |
195 | - foreach ($this->fields as $name => $_) { |
|
209 | + foreach ($this->fields as $name => $_) |
|
210 | + { |
|
196 | 211 | $result[$name] = $this->getField($name, null, $filter); |
197 | 212 | } |
198 | 213 | |
@@ -259,10 +274,14 @@ discard block |
||
259 | 274 | public function getValue(): array |
260 | 275 | { |
261 | 276 | $result = []; |
262 | - foreach ($this->fields as $field => $value) { |
|
263 | - if ($value instanceof ValueInterface) { |
|
277 | + foreach ($this->fields as $field => $value) |
|
278 | + { |
|
279 | + if ($value instanceof ValueInterface) |
|
280 | + { |
|
264 | 281 | $result[$field] = $value->getValue(); |
265 | - } else { |
|
282 | + } |
|
283 | + else |
|
284 | + { |
|
266 | 285 | $result[$field] = $value; |
267 | 286 | } |
268 | 287 | } |
@@ -355,7 +374,8 @@ discard block |
||
355 | 374 | $value, |
356 | 375 | array $context = [] |
357 | 376 | ): ValueInterface { |
358 | - if (!is_string($type) || !class_exists($type)) { |
|
377 | + if (!is_string($type) || !class_exists($type)) |
|
378 | + { |
|
359 | 379 | throw new EntityException( |
360 | 380 | "Unable to create accessor for field `{$name}` in " . static::class |
361 | 381 | ); |
@@ -377,10 +397,14 @@ discard block |
||
377 | 397 | { |
378 | 398 | $getter = $this->getMutator($name, ModelSchema::MUTATOR_GETTER); |
379 | 399 | |
380 | - if ($filter && !empty($getter)) { |
|
381 | - try { |
|
400 | + if ($filter && !empty($getter)) |
|
401 | + { |
|
402 | + try |
|
403 | + { |
|
382 | 404 | return call_user_func($getter, $value); |
383 | - } catch (\Exception $e) { |
|
405 | + } |
|
406 | + catch (\Exception $e) |
|
407 | + { |
|
384 | 408 | //Trying to filter null value, every filter must support it |
385 | 409 | return call_user_func($getter, null); |
386 | 410 | } |
@@ -399,13 +423,19 @@ discard block |
||
399 | 423 | { |
400 | 424 | $setter = $this->getMutator($name, ModelSchema::MUTATOR_SETTER); |
401 | 425 | |
402 | - if (!empty($setter)) { |
|
403 | - try { |
|
426 | + if (!empty($setter)) |
|
427 | + { |
|
428 | + try |
|
429 | + { |
|
404 | 430 | $this->fields[$name] = call_user_func($setter, $value); |
405 | - } catch (\Exception $e) { |
|
431 | + } |
|
432 | + catch (\Exception $e) |
|
433 | + { |
|
406 | 434 | //Exceptional situation, we are choosing to keep original field value |
407 | 435 | } |
408 | - } else { |
|
436 | + } |
|
437 | + else |
|
438 | + { |
|
409 | 439 | $this->fields[$name] = $value; |
410 | 440 | } |
411 | 441 | } |
@@ -419,13 +449,17 @@ discard block |
||
419 | 449 | */ |
420 | 450 | private function thoughValue($type, string $name, $value): void |
421 | 451 | { |
422 | - if (array_key_exists($name, $this->fields)) { |
|
452 | + if (array_key_exists($name, $this->fields)) |
|
453 | + { |
|
423 | 454 | $field = $this->fields[$name]; |
424 | - } else { |
|
455 | + } |
|
456 | + else |
|
457 | + { |
|
425 | 458 | $field = null; |
426 | 459 | } |
427 | 460 | |
428 | - if (empty($field) || !($field instanceof ValueInterface)) { |
|
461 | + if (empty($field) || !($field instanceof ValueInterface)) |
|
462 | + { |
|
429 | 463 | //New field representation |
430 | 464 | $field = $this->createValue($type, $name, $value); |
431 | 465 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Spiral\Scaffolder; |
13 | 13 | |
14 | -if (!function_exists('trimPostfix')) { |
|
14 | +if (!function_exists('trimPostfix')){ |
|
15 | 15 | /** |
16 | 16 | * @param string $name |
17 | 17 | * @param string $postfix |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | -if (!function_exists('isAssociativeArray')) { |
|
29 | +if (!function_exists('isAssociativeArray')){ |
|
30 | 30 | /** |
31 | 31 | * @param array $array |
32 | 32 | * @return bool |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | function isAssociativeArray(array $array): bool |
36 | 36 | { |
37 | 37 | $keys = []; |
38 | - foreach ($array as $key => $_) { |
|
39 | - if (!is_int($key)) { |
|
38 | + foreach ($array as $key => $_){ |
|
39 | + if (!is_int($key)){ |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | - if ($key !== count($keys)) { |
|
43 | + if ($key !== count($keys)){ |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | -if (!function_exists('defineArrayType')) { |
|
54 | +if (!function_exists('defineArrayType')){ |
|
55 | 55 | /** |
56 | 56 | * @param array $array |
57 | 57 | * @param string|null $failureType |
@@ -11,7 +11,8 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Spiral\Scaffolder; |
13 | 13 | |
14 | -if (!function_exists('trimPostfix')) { |
|
14 | +if (!function_exists('trimPostfix')) |
|
15 | +{ |
|
15 | 16 | /** |
16 | 17 | * @param string $name |
17 | 18 | * @param string $postfix |
@@ -26,7 +27,8 @@ discard block |
||
26 | 27 | } |
27 | 28 | } |
28 | 29 | |
29 | -if (!function_exists('isAssociativeArray')) { |
|
30 | +if (!function_exists('isAssociativeArray')) |
|
31 | +{ |
|
30 | 32 | /** |
31 | 33 | * @param array $array |
32 | 34 | * @return bool |
@@ -35,12 +37,15 @@ discard block |
||
35 | 37 | function isAssociativeArray(array $array): bool |
36 | 38 | { |
37 | 39 | $keys = []; |
38 | - foreach ($array as $key => $_) { |
|
39 | - if (!is_int($key)) { |
|
40 | + foreach ($array as $key => $_) |
|
41 | + { |
|
42 | + if (!is_int($key)) |
|
43 | + { |
|
40 | 44 | return true; |
41 | 45 | } |
42 | 46 | |
43 | - if ($key !== count($keys)) { |
|
47 | + if ($key !== count($keys)) |
|
48 | + { |
|
44 | 49 | return true; |
45 | 50 | } |
46 | 51 | |
@@ -51,7 +56,8 @@ discard block |
||
51 | 56 | } |
52 | 57 | } |
53 | 58 | |
54 | -if (!function_exists('defineArrayType')) { |
|
59 | +if (!function_exists('defineArrayType')) |
|
60 | +{ |
|
55 | 61 | /** |
56 | 62 | * @param array $array |
57 | 63 | * @param string|null $failureType |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | DirectoriesInterface::class, |
50 | 50 | new Directories( |
51 | 51 | [ |
52 | - 'app' => __DIR__ . '/fixtures', |
|
53 | - 'cache' => __DIR__ . '/cache' |
|
52 | + 'app' => __DIR__.'/fixtures', |
|
53 | + 'cache' => __DIR__.'/cache' |
|
54 | 54 | ] |
55 | 55 | ) |
56 | 56 | ); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $this->container->bind( |
60 | 60 | ConfiguratorInterface::class, |
61 | 61 | new ConfigManager( |
62 | - new DirectoryLoader(__DIR__ . '/config/', $this->container), |
|
62 | + new DirectoryLoader(__DIR__.'/config/', $this->container), |
|
63 | 63 | true |
64 | 64 | ) |
65 | 65 | ); |
@@ -35,13 +35,13 @@ |
||
35 | 35 | |
36 | 36 | public function testCache(): void |
37 | 37 | { |
38 | - $this->assertCount(0, $this->files->getFiles(__DIR__ . '/cache/', '*.php')); |
|
38 | + $this->assertCount(0, $this->files->getFiles(__DIR__.'/cache/', '*.php')); |
|
39 | 39 | |
40 | 40 | $s = $this->getStempler(); |
41 | 41 | $this->assertSame('test', $s->get('test', new ViewContext())->render([])); |
42 | - $this->assertCount(2, $this->files->getFiles(__DIR__ . '/cache/', '*.php')); |
|
42 | + $this->assertCount(2, $this->files->getFiles(__DIR__.'/cache/', '*.php')); |
|
43 | 43 | |
44 | 44 | $s->reset('test', new ViewContext()); |
45 | - $this->assertCount(0, $this->files->getFiles(__DIR__ . '/../cache/', '*.php')); |
|
45 | + $this->assertCount(0, $this->files->getFiles(__DIR__.'/../cache/', '*.php')); |
|
46 | 46 | } |
47 | 47 | } |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | { |
58 | 58 | $s = $this->getStempler(); |
59 | 59 | |
60 | - try { |
|
60 | + try{ |
|
61 | 61 | $s->get('echo', new ViewContext())->render(); |
62 | - } catch (RenderException $e) { |
|
62 | + }catch (RenderException $e){ |
|
63 | 63 | $t = $e->getUserTrace()[0]; |
64 | 64 | |
65 | 65 | $this->assertSame(2, $t['line']); |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | { |
72 | 72 | $s = $this->getStempler(); |
73 | 73 | |
74 | - try { |
|
74 | + try{ |
|
75 | 75 | $s->get('other:echo-in', new ViewContext())->render(); |
76 | - } catch (RenderException $e) { |
|
76 | + }catch (RenderException $e){ |
|
77 | 77 | $t = $e->getUserTrace(); |
78 | 78 | $this->assertCount(2, $t); |
79 | 79 | |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | { |
90 | 90 | $twig = $this->getStempler(); |
91 | 91 | |
92 | - try { |
|
92 | + try{ |
|
93 | 93 | $twig->get('other:bad', new ViewContext()); |
94 | - } catch (CompileException $e) { |
|
94 | + }catch (CompileException $e){ |
|
95 | 95 | $this->assertStringContainsString('bad.dark.php', $e->getFile()); |
96 | 96 | } |
97 | 97 | } |
@@ -57,9 +57,12 @@ discard block |
||
57 | 57 | { |
58 | 58 | $s = $this->getStempler(); |
59 | 59 | |
60 | - try { |
|
60 | + try |
|
61 | + { |
|
61 | 62 | $s->get('echo', new ViewContext())->render(); |
62 | - } catch (RenderException $e) { |
|
63 | + } |
|
64 | + catch (RenderException $e) |
|
65 | + { |
|
63 | 66 | $t = $e->getUserTrace()[0]; |
64 | 67 | |
65 | 68 | $this->assertSame(2, $t['line']); |
@@ -71,9 +74,12 @@ discard block |
||
71 | 74 | { |
72 | 75 | $s = $this->getStempler(); |
73 | 76 | |
74 | - try { |
|
77 | + try |
|
78 | + { |
|
75 | 79 | $s->get('other:echo-in', new ViewContext())->render(); |
76 | - } catch (RenderException $e) { |
|
80 | + } |
|
81 | + catch (RenderException $e) |
|
82 | + { |
|
77 | 83 | $t = $e->getUserTrace(); |
78 | 84 | $this->assertCount(2, $t); |
79 | 85 | |
@@ -89,9 +95,12 @@ discard block |
||
89 | 95 | { |
90 | 96 | $twig = $this->getStempler(); |
91 | 97 | |
92 | - try { |
|
98 | + try |
|
99 | + { |
|
93 | 100 | $twig->get('other:bad', new ViewContext()); |
94 | - } catch (CompileException $e) { |
|
101 | + } |
|
102 | + catch (CompileException $e) |
|
103 | + { |
|
95 | 104 | $this->assertStringContainsString('bad.dark.php', $e->getFile()); |
96 | 105 | } |
97 | 106 | } |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
34 | 34 | { |
35 | - if (!$node instanceof Tag) { |
|
35 | + if (!$node instanceof Tag){ |
|
36 | 36 | return; |
37 | 37 | } |
38 | 38 | |
39 | 39 | $flatten = []; |
40 | - foreach ($node->nodes as $child) { |
|
41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
42 | - foreach ($child->nodes as $childNode) { |
|
40 | + foreach ($node->nodes as $child){ |
|
41 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate){ |
|
42 | + foreach ($child->nodes as $childNode){ |
|
43 | 43 | $flatten[] = $childNode; |
44 | 44 | } |
45 | 45 | continue; |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | private function mergeRaw(array $nodes): array |
66 | 66 | { |
67 | 67 | $result = []; |
68 | - foreach ($nodes as $node) { |
|
68 | + foreach ($nodes as $node){ |
|
69 | 69 | if ( |
70 | 70 | $node instanceof Raw |
71 | 71 | && isset($result[count($result) - 1]) |
72 | 72 | && $result[count($result) - 1] instanceof Raw |
73 | - ) { |
|
73 | + ){ |
|
74 | 74 | $result[count($result) - 1]->content .= $node->content; |
75 | 75 | continue; |
76 | 76 | } |
@@ -32,14 +32,18 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function enterNode($node, VisitorContext $ctx): void |
34 | 34 | { |
35 | - if (!$node instanceof Tag) { |
|
35 | + if (!$node instanceof Tag) |
|
36 | + { |
|
36 | 37 | return; |
37 | 38 | } |
38 | 39 | |
39 | 40 | $flatten = []; |
40 | - foreach ($node->nodes as $child) { |
|
41 | - if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) { |
|
42 | - foreach ($child->nodes as $childNode) { |
|
41 | + foreach ($node->nodes as $child) |
|
42 | + { |
|
43 | + if ($child instanceof Block || $child instanceof Template || $child instanceof Aggregate) |
|
44 | + { |
|
45 | + foreach ($child->nodes as $childNode) |
|
46 | + { |
|
43 | 47 | $flatten[] = $childNode; |
44 | 48 | } |
45 | 49 | continue; |
@@ -65,7 +69,8 @@ discard block |
||
65 | 69 | private function mergeRaw(array $nodes): array |
66 | 70 | { |
67 | 71 | $result = []; |
68 | - foreach ($nodes as $node) { |
|
72 | + foreach ($nodes as $node) |
|
73 | + { |
|
69 | 74 | if ( |
70 | 75 | $node instanceof Raw |
71 | 76 | && isset($result[count($result) - 1]) |
@@ -40,30 +40,30 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function enterNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag){ |
|
44 | 44 | return null; |
45 | 45 | } |
46 | 46 | |
47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
47 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)){ |
|
48 | 48 | // raw nodes |
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $level = $this->getLevel($ctx); |
53 | - if ($level === null) { |
|
53 | + if ($level === null){ |
|
54 | 54 | // not available in some contexts |
55 | 55 | return null; |
56 | 56 | } |
57 | 57 | |
58 | - foreach ($node->nodes as $i => $child) { |
|
59 | - if (!$child instanceof Raw) { |
|
58 | + foreach ($node->nodes as $i => $child){ |
|
59 | + if (!$child instanceof Raw){ |
|
60 | 60 | continue; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $position = self::BETWEEN_TAGS; |
64 | - if (!isset($node->nodes[$i + 1])) { |
|
64 | + if (!isset($node->nodes[$i + 1])){ |
|
65 | 65 | $position = self::BEFORE_CLOSE; |
66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
66 | + } elseif ($node->nodes[$i + 1] instanceof PHP){ |
|
67 | 67 | $position = self::BEFORE_PHP; |
68 | 68 | } |
69 | 69 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
92 | 92 | { |
93 | - if (strpos($content, "\n") === false) { |
|
93 | + if (strpos($content, "\n") === false){ |
|
94 | 94 | // no need to do anything |
95 | 95 | return $content; |
96 | 96 | } |
@@ -98,44 +98,44 @@ discard block |
||
98 | 98 | // we have to apply special rules to the first and the last lines |
99 | 99 | $lines = explode("\n", $content); |
100 | 100 | |
101 | - foreach ($lines as $i => $line) { |
|
102 | - if (trim($line) === '' && $i !== 0) { |
|
101 | + foreach ($lines as $i => $line){ |
|
102 | + if (trim($line) === '' && $i !== 0){ |
|
103 | 103 | unset($lines[$i]); |
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | 107 | $lines = array_values($lines); |
108 | - if (count($lines) === 0) { |
|
108 | + if (count($lines) === 0){ |
|
109 | 109 | $lines[] = ''; |
110 | 110 | } |
111 | 111 | |
112 | 112 | $result = ''; |
113 | - foreach ($lines as $i => $line) { |
|
114 | - if (trim($line) !== '') { |
|
115 | - if ($i === 0) { |
|
113 | + foreach ($lines as $i => $line){ |
|
114 | + if (trim($line) !== ''){ |
|
115 | + if ($i === 0){ |
|
116 | 116 | $line = rtrim($line); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $line = trim($line); |
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
122 | - if ($i !== (count($lines) - 1)) { |
|
123 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
122 | + if ($i !== (count($lines) - 1)){ |
|
123 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // working with last line |
128 | - if ($position === self::BEFORE_PHP) { |
|
129 | - $result .= $line . "\n"; |
|
128 | + if ($position === self::BEFORE_PHP){ |
|
129 | + $result .= $line."\n"; |
|
130 | 130 | break; |
131 | 131 | } |
132 | 132 | |
133 | - if ($position === self::BEFORE_CLOSE) { |
|
134 | - $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
|
133 | + if ($position === self::BEFORE_CLOSE){ |
|
134 | + $result .= $line."\n".str_repeat(self::INDENT, max($level - 1, 0)); |
|
135 | 135 | break; |
136 | 136 | } |
137 | 137 | |
138 | - $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
|
138 | + $result .= $line."\n".str_repeat(self::INDENT, $level); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | return $result; |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | private function getLevel(VisitorContext $ctx): ?int |
149 | 149 | { |
150 | 150 | $level = 0; |
151 | - foreach ($ctx->getScope() as $node) { |
|
152 | - if ($node instanceof Attr) { |
|
151 | + foreach ($ctx->getScope() as $node){ |
|
152 | + if ($node instanceof Attr){ |
|
153 | 153 | return null; |
154 | 154 | } |
155 | 155 | |
156 | - if ($node instanceof Block || $node instanceof Template) { |
|
156 | + if ($node instanceof Block || $node instanceof Template){ |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
175 | 175 | { |
176 | - if (!$joinMultiple) { |
|
176 | + if (!$joinMultiple){ |
|
177 | 177 | return str_replace("\r\n", "\n", $string); |
178 | 178 | } |
179 | 179 |
@@ -40,30 +40,38 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function enterNode($node, VisitorContext $ctx) |
42 | 42 | { |
43 | - if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) { |
|
43 | + if (!$node instanceof Template && !$node instanceof Block && !$node instanceof Tag) |
|
44 | + { |
|
44 | 45 | return null; |
45 | 46 | } |
46 | 47 | |
47 | - if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) { |
|
48 | + if ($node instanceof Tag && in_array($node->name, self::EXCLUDE)) |
|
49 | + { |
|
48 | 50 | // raw nodes |
49 | 51 | return null; |
50 | 52 | } |
51 | 53 | |
52 | 54 | $level = $this->getLevel($ctx); |
53 | - if ($level === null) { |
|
55 | + if ($level === null) |
|
56 | + { |
|
54 | 57 | // not available in some contexts |
55 | 58 | return null; |
56 | 59 | } |
57 | 60 | |
58 | - foreach ($node->nodes as $i => $child) { |
|
59 | - if (!$child instanceof Raw) { |
|
61 | + foreach ($node->nodes as $i => $child) |
|
62 | + { |
|
63 | + if (!$child instanceof Raw) |
|
64 | + { |
|
60 | 65 | continue; |
61 | 66 | } |
62 | 67 | |
63 | 68 | $position = self::BETWEEN_TAGS; |
64 | - if (!isset($node->nodes[$i + 1])) { |
|
69 | + if (!isset($node->nodes[$i + 1])) |
|
70 | + { |
|
65 | 71 | $position = self::BEFORE_CLOSE; |
66 | - } elseif ($node->nodes[$i + 1] instanceof PHP) { |
|
72 | + } |
|
73 | + elseif ($node->nodes[$i + 1] instanceof PHP) |
|
74 | + { |
|
67 | 75 | $position = self::BEFORE_PHP; |
68 | 76 | } |
69 | 77 | |
@@ -90,7 +98,8 @@ discard block |
||
90 | 98 | */ |
91 | 99 | private function indentContent(string $content, int $level, int $position = self::BETWEEN_TAGS) |
92 | 100 | { |
93 | - if (strpos($content, "\n") === false) { |
|
101 | + if (strpos($content, "\n") === false) |
|
102 | + { |
|
94 | 103 | // no need to do anything |
95 | 104 | return $content; |
96 | 105 | } |
@@ -98,39 +107,50 @@ discard block |
||
98 | 107 | // we have to apply special rules to the first and the last lines |
99 | 108 | $lines = explode("\n", $content); |
100 | 109 | |
101 | - foreach ($lines as $i => $line) { |
|
102 | - if (trim($line) === '' && $i !== 0) { |
|
110 | + foreach ($lines as $i => $line) |
|
111 | + { |
|
112 | + if (trim($line) === '' && $i !== 0) |
|
113 | + { |
|
103 | 114 | unset($lines[$i]); |
104 | 115 | } |
105 | 116 | } |
106 | 117 | |
107 | 118 | $lines = array_values($lines); |
108 | - if (count($lines) === 0) { |
|
119 | + if (count($lines) === 0) |
|
120 | + { |
|
109 | 121 | $lines[] = ''; |
110 | 122 | } |
111 | 123 | |
112 | 124 | $result = ''; |
113 | - foreach ($lines as $i => $line) { |
|
114 | - if (trim($line) !== '') { |
|
115 | - if ($i === 0) { |
|
125 | + foreach ($lines as $i => $line) |
|
126 | + { |
|
127 | + if (trim($line) !== '') |
|
128 | + { |
|
129 | + if ($i === 0) |
|
130 | + { |
|
116 | 131 | $line = rtrim($line); |
117 | - } else { |
|
132 | + } |
|
133 | + else |
|
134 | + { |
|
118 | 135 | $line = trim($line); |
119 | 136 | } |
120 | 137 | } |
121 | 138 | |
122 | - if ($i !== (count($lines) - 1)) { |
|
139 | + if ($i !== (count($lines) - 1)) |
|
140 | + { |
|
123 | 141 | $result .= $line . "\n" . str_repeat(self::INDENT, $level); |
124 | 142 | continue; |
125 | 143 | } |
126 | 144 | |
127 | 145 | // working with last line |
128 | - if ($position === self::BEFORE_PHP) { |
|
146 | + if ($position === self::BEFORE_PHP) |
|
147 | + { |
|
129 | 148 | $result .= $line . "\n"; |
130 | 149 | break; |
131 | 150 | } |
132 | 151 | |
133 | - if ($position === self::BEFORE_CLOSE) { |
|
152 | + if ($position === self::BEFORE_CLOSE) |
|
153 | + { |
|
134 | 154 | $result .= $line . "\n" . str_repeat(self::INDENT, max($level - 1, 0)); |
135 | 155 | break; |
136 | 156 | } |
@@ -148,12 +168,15 @@ discard block |
||
148 | 168 | private function getLevel(VisitorContext $ctx): ?int |
149 | 169 | { |
150 | 170 | $level = 0; |
151 | - foreach ($ctx->getScope() as $node) { |
|
152 | - if ($node instanceof Attr) { |
|
171 | + foreach ($ctx->getScope() as $node) |
|
172 | + { |
|
173 | + if ($node instanceof Attr) |
|
174 | + { |
|
153 | 175 | return null; |
154 | 176 | } |
155 | 177 | |
156 | - if ($node instanceof Block || $node instanceof Template) { |
|
178 | + if ($node instanceof Block || $node instanceof Template) |
|
179 | + { |
|
157 | 180 | continue; |
158 | 181 | } |
159 | 182 | |
@@ -173,7 +196,8 @@ discard block |
||
173 | 196 | */ |
174 | 197 | private function normalizeEndings(string $string, bool $joinMultiple = true): string |
175 | 198 | { |
176 | - if (!$joinMultiple) { |
|
199 | + if (!$joinMultiple) |
|
200 | + { |
|
177 | 201 | return str_replace("\r\n", "\n", $string); |
178 | 202 | } |
179 | 203 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | protected function each(callable $resolver): iterable |
20 | 20 | { |
21 | - foreach ($this->readers as $reader) { |
|
21 | + foreach ($this->readers as $reader){ |
|
22 | 22 | yield from $resolver($reader); |
23 | 23 | } |
24 | 24 | } |
@@ -18,7 +18,8 @@ |
||
18 | 18 | */ |
19 | 19 | protected function each(callable $resolver): iterable |
20 | 20 | { |
21 | - foreach ($this->readers as $reader) { |
|
21 | + foreach ($this->readers as $reader) |
|
22 | + { |
|
22 | 23 | yield from $resolver($reader); |
23 | 24 | } |
24 | 25 | } |
@@ -18,10 +18,10 @@ |
||
18 | 18 | */ |
19 | 19 | protected function each(callable $resolver): iterable |
20 | 20 | { |
21 | - foreach ($this->readers as $reader) { |
|
21 | + foreach ($this->readers as $reader){ |
|
22 | 22 | $result = $this->iterableToArray($resolver($reader)); |
23 | 23 | |
24 | - if (\count($result) > 0) { |
|
24 | + if (\count($result) > 0){ |
|
25 | 25 | return $result; |
26 | 26 | } |
27 | 27 | } |
@@ -18,10 +18,12 @@ |
||
18 | 18 | */ |
19 | 19 | protected function each(callable $resolver): iterable |
20 | 20 | { |
21 | - foreach ($this->readers as $reader) { |
|
21 | + foreach ($this->readers as $reader) |
|
22 | + { |
|
22 | 23 | $result = $this->iterableToArray($resolver($reader)); |
23 | 24 | |
24 | - if (\count($result) > 0) { |
|
25 | + if (\count($result) > 0) |
|
26 | + { |
|
25 | 27 | return $result; |
26 | 28 | } |
27 | 29 | } |