@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | ->getReflectionConstants() |
44 | 44 | ; |
45 | 45 | |
46 | - foreach ($constants as $reflection) { |
|
47 | - if ($reflection->getName() === $name) { |
|
46 | + foreach ($constants as $reflection){ |
|
47 | + if ($reflection->getName() === $name){ |
|
48 | 48 | return $reflection; |
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - throw new \ReflectionException('Constant ' . $name . ' not found'); |
|
52 | + throw new \ReflectionException('Constant '.$name.' not found'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | protected function getReflectionFunctionParameter(string $function, string $name): \ReflectionParameter |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ->getParameters() |
59 | 59 | ; |
60 | 60 | |
61 | - foreach ($parameters as $reflection) { |
|
62 | - if ($reflection->getName() === $name) { |
|
61 | + foreach ($parameters as $reflection){ |
|
62 | + if ($reflection->getName() === $name){ |
|
63 | 63 | return $reflection; |
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | - throw new \ReflectionException('Parameter ' . $name . ' not found'); |
|
67 | + throw new \ReflectionException('Parameter '.$name.' not found'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | protected function getReflectionMethodParameter(string $class, string $method, string $name): \ReflectionParameter |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | ->getParameters() |
74 | 74 | ; |
75 | 75 | |
76 | - foreach ($parameters as $reflection) { |
|
77 | - if ($reflection->getName() === $name) { |
|
76 | + foreach ($parameters as $reflection){ |
|
77 | + if ($reflection->getName() === $name){ |
|
78 | 78 | return $reflection; |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - throw new \ReflectionException('Parameter ' . $name . ' not found'); |
|
82 | + throw new \ReflectionException('Parameter '.$name.' not found'); |
|
83 | 83 | } |
84 | 84 | } |
@@ -43,8 +43,10 @@ discard block |
||
43 | 43 | ->getReflectionConstants() |
44 | 44 | ; |
45 | 45 | |
46 | - foreach ($constants as $reflection) { |
|
47 | - if ($reflection->getName() === $name) { |
|
46 | + foreach ($constants as $reflection) |
|
47 | + { |
|
48 | + if ($reflection->getName() === $name) |
|
49 | + { |
|
48 | 50 | return $reflection; |
49 | 51 | } |
50 | 52 | } |
@@ -58,8 +60,10 @@ discard block |
||
58 | 60 | ->getParameters() |
59 | 61 | ; |
60 | 62 | |
61 | - foreach ($parameters as $reflection) { |
|
62 | - if ($reflection->getName() === $name) { |
|
63 | + foreach ($parameters as $reflection) |
|
64 | + { |
|
65 | + if ($reflection->getName() === $name) |
|
66 | + { |
|
63 | 67 | return $reflection; |
64 | 68 | } |
65 | 69 | } |
@@ -73,8 +77,10 @@ discard block |
||
73 | 77 | ->getParameters() |
74 | 78 | ; |
75 | 79 | |
76 | - foreach ($parameters as $reflection) { |
|
77 | - if ($reflection->getName() === $name) { |
|
80 | + foreach ($parameters as $reflection) |
|
81 | + { |
|
82 | + if ($reflection->getName() === $name) |
|
83 | + { |
|
78 | 84 | return $reflection; |
79 | 85 | } |
80 | 86 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | function hasKey(array $array, $search): bool |
23 | 23 | { |
24 | - foreach ($array as $key => $_) { |
|
25 | - if (equals($key, $search)) { |
|
24 | + foreach ($array as $key => $_){ |
|
25 | + if (equals($key, $search)){ |
|
26 | 26 | return true; |
27 | 27 | } |
28 | 28 | } |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | */ |
38 | 38 | function hasValue(array $array, $search): bool |
39 | 39 | { |
40 | - foreach ($array as $value) { |
|
41 | - if (equals($value, $search)) { |
|
40 | + foreach ($array as $value){ |
|
41 | + if (equals($value, $search)){ |
|
42 | 42 | return true; |
43 | 43 | } |
44 | 44 | } |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | */ |
57 | 57 | function getValue(array $array, string $search) |
58 | 58 | { |
59 | - foreach ($array as $key => $value) { |
|
60 | - if (equals($key, $search)) { |
|
59 | + foreach ($array as $key => $value){ |
|
60 | + if (equals($key, $search)){ |
|
61 | 61 | return $value; |
62 | 62 | } |
63 | 63 | } |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function equals($value1, $value2): bool |
75 | 75 | { |
76 | - if (is_string($value1) && is_string($value2) && strcasecmp($value1, $value2) === 0) { |
|
76 | + if (is_string($value1) && is_string($value2) && strcasecmp($value1, $value2) === 0){ |
|
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | |
80 | - if (is_numeric($value1) && is_numeric($value2) && strcasecmp((string)$value1, (string)$value2) === 0) { |
|
80 | + if (is_numeric($value1) && is_numeric($value2) && strcasecmp((string)$value1, (string)$value2) === 0){ |
|
81 | 81 | return true; |
82 | 82 | } |
83 | 83 |
@@ -21,8 +21,10 @@ discard block |
||
21 | 21 | */ |
22 | 22 | function hasKey(array $array, $search): bool |
23 | 23 | { |
24 | - foreach ($array as $key => $_) { |
|
25 | - if (equals($key, $search)) { |
|
24 | + foreach ($array as $key => $_) |
|
25 | + { |
|
26 | + if (equals($key, $search)) |
|
27 | + { |
|
26 | 28 | return true; |
27 | 29 | } |
28 | 30 | } |
@@ -37,8 +39,10 @@ discard block |
||
37 | 39 | */ |
38 | 40 | function hasValue(array $array, $search): bool |
39 | 41 | { |
40 | - foreach ($array as $value) { |
|
41 | - if (equals($value, $search)) { |
|
42 | + foreach ($array as $value) |
|
43 | + { |
|
44 | + if (equals($value, $search)) |
|
45 | + { |
|
42 | 46 | return true; |
43 | 47 | } |
44 | 48 | } |
@@ -56,8 +60,10 @@ discard block |
||
56 | 60 | */ |
57 | 61 | function getValue(array $array, string $search) |
58 | 62 | { |
59 | - foreach ($array as $key => $value) { |
|
60 | - if (equals($key, $search)) { |
|
63 | + foreach ($array as $key => $value) |
|
64 | + { |
|
65 | + if (equals($key, $search)) |
|
66 | + { |
|
61 | 67 | return $value; |
62 | 68 | } |
63 | 69 | } |
@@ -73,11 +79,13 @@ discard block |
||
73 | 79 | */ |
74 | 80 | function equals($value1, $value2): bool |
75 | 81 | { |
76 | - if (is_string($value1) && is_string($value2) && strcasecmp($value1, $value2) === 0) { |
|
82 | + if (is_string($value1) && is_string($value2) && strcasecmp($value1, $value2) === 0) |
|
83 | + { |
|
77 | 84 | return true; |
78 | 85 | } |
79 | 86 | |
80 | - if (is_numeric($value1) && is_numeric($value2) && strcasecmp((string)$value1, (string)$value2) === 0) { |
|
87 | + if (is_numeric($value1) && is_numeric($value2) && strcasecmp((string)$value1, (string)$value2) === 0) |
|
88 | + { |
|
81 | 89 | return true; |
82 | 90 | } |
83 | 91 |
@@ -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 |
@@ -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 | } |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | public function getGenerators(): array |
86 | 86 | { |
87 | 87 | $result = []; |
88 | - foreach ($this->generators as $group) { |
|
89 | - foreach ($group as $generator) { |
|
90 | - if (is_object($generator) && !$generator instanceof Container\Autowire) { |
|
88 | + foreach ($this->generators as $group){ |
|
89 | + foreach ($group as $generator){ |
|
90 | + if (is_object($generator) && !$generator instanceof Container\Autowire){ |
|
91 | 91 | $result[] = $generator; |
92 | - } else { |
|
92 | + }else{ |
|
93 | 93 | $result[] = $this->container->get($generator); |
94 | 94 | } |
95 | 95 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | protected function schema(MemoryInterface $memory): SchemaInterface |
108 | 108 | { |
109 | 109 | $schemaCompiler = SchemaCompiler::fromMemory($memory); |
110 | - if ($schemaCompiler->isEmpty()) { |
|
110 | + if ($schemaCompiler->isEmpty()){ |
|
111 | 111 | $schemaCompiler = SchemaCompiler::compile( |
112 | 112 | $this->container->get(Registry::class), |
113 | 113 | $this->getGenerators() |
@@ -85,11 +85,16 @@ discard block |
||
85 | 85 | public function getGenerators(): array |
86 | 86 | { |
87 | 87 | $result = []; |
88 | - foreach ($this->generators as $group) { |
|
89 | - foreach ($group as $generator) { |
|
90 | - if (is_object($generator) && !$generator instanceof Container\Autowire) { |
|
88 | + foreach ($this->generators as $group) |
|
89 | + { |
|
90 | + foreach ($group as $generator) |
|
91 | + { |
|
92 | + if (is_object($generator) && !$generator instanceof Container\Autowire) |
|
93 | + { |
|
91 | 94 | $result[] = $generator; |
92 | - } else { |
|
95 | + } |
|
96 | + else |
|
97 | + { |
|
93 | 98 | $result[] = $this->container->get($generator); |
94 | 99 | } |
95 | 100 | } |
@@ -107,7 +112,8 @@ discard block |
||
107 | 112 | protected function schema(MemoryInterface $memory): SchemaInterface |
108 | 113 | { |
109 | 114 | $schemaCompiler = SchemaCompiler::fromMemory($memory); |
110 | - if ($schemaCompiler->isEmpty()) { |
|
115 | + if ($schemaCompiler->isEmpty()) |
|
116 | + { |
|
111 | 117 | $schemaCompiler = SchemaCompiler::compile( |
112 | 118 | $this->container->get(Registry::class), |
113 | 119 | $this->getGenerators() |
@@ -44,7 +44,7 @@ |
||
44 | 44 | ); |
45 | 45 | $schemaCompiler->toMemory($memory); |
46 | 46 | |
47 | - if ($show->hasChanges()) { |
|
47 | + if ($show->hasChanges()){ |
|
48 | 48 | $this->writeln("\n<info>ORM Schema has been synchronized</info>"); |
49 | 49 | } |
50 | 50 | } |
@@ -44,7 +44,8 @@ |
||
44 | 44 | ); |
45 | 45 | $schemaCompiler->toMemory($memory); |
46 | 46 | |
47 | - if ($show->hasChanges()) { |
|
47 | + if ($show->hasChanges()) |
|
48 | + { |
|
48 | 49 | $this->writeln("\n<info>ORM Schema has been synchronized</info>"); |
49 | 50 | } |
50 | 51 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | Migrator $migrator, |
51 | 51 | Console $console |
52 | 52 | ): void { |
53 | - if (!$this->verifyConfigured()) { |
|
53 | + if (!$this->verifyConfigured()){ |
|
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - foreach ($migrator->getMigrations() as $migration) { |
|
58 | - if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) { |
|
57 | + foreach ($migrator->getMigrations() as $migration){ |
|
58 | + if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED){ |
|
59 | 59 | $this->writeln('<fg=red>Outstanding migrations found, run `migrate` first.</fg=red>'); |
60 | 60 | return; |
61 | 61 | } |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | ); |
70 | 70 | $schemaCompiler->toMemory($memory); |
71 | 71 | |
72 | - if ($show->hasChanges()) { |
|
72 | + if ($show->hasChanges()){ |
|
73 | 73 | (new Compiler())->compile($registry, [$migrations]); |
74 | 74 | |
75 | - if ($this->option('run')) { |
|
75 | + if ($this->option('run')){ |
|
76 | 76 | $console->run('migrate', [], $this->output); |
77 | 77 | } |
78 | 78 | } |
@@ -50,12 +50,15 @@ discard block |
||
50 | 50 | Migrator $migrator, |
51 | 51 | Console $console |
52 | 52 | ): void { |
53 | - if (!$this->verifyConfigured()) { |
|
53 | + if (!$this->verifyConfigured()) |
|
54 | + { |
|
54 | 55 | return; |
55 | 56 | } |
56 | 57 | |
57 | - foreach ($migrator->getMigrations() as $migration) { |
|
58 | - if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) { |
|
58 | + foreach ($migrator->getMigrations() as $migration) |
|
59 | + { |
|
60 | + if ($migration->getState()->getStatus() !== State::STATUS_EXECUTED) |
|
61 | + { |
|
59 | 62 | $this->writeln('<fg=red>Outstanding migrations found, run `migrate` first.</fg=red>'); |
60 | 63 | return; |
61 | 64 | } |
@@ -69,10 +72,12 @@ discard block |
||
69 | 72 | ); |
70 | 73 | $schemaCompiler->toMemory($memory); |
71 | 74 | |
72 | - if ($show->hasChanges()) { |
|
75 | + if ($show->hasChanges()) |
|
76 | + { |
|
73 | 77 | (new Compiler())->compile($registry, [$migrations]); |
74 | 78 | |
75 | - if ($this->option('run')) { |
|
79 | + if ($this->option('run')) |
|
80 | + { |
|
76 | 81 | $console->run('migrate', [], $this->output); |
77 | 82 | } |
78 | 83 | } |