@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | { |
24 | 24 | $reflection = new \ReflectionClass($object); |
25 | 25 | |
26 | - if ($reflection->implementsInterface(QueueableInterface::class)) { |
|
26 | + if ($reflection->implementsInterface(QueueableInterface::class)) |
|
27 | + { |
|
27 | 28 | return true; |
28 | 29 | } |
29 | 30 | |
@@ -38,11 +39,13 @@ discard block |
||
38 | 39 | $reflection = new \ReflectionClass($object); |
39 | 40 | |
40 | 41 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
41 | - if ($attribute !== null) { |
|
42 | + if ($attribute !== null) |
|
43 | + { |
|
42 | 44 | return $attribute->queue; |
43 | 45 | } |
44 | 46 | |
45 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
47 | + if (\is_object($object) && $reflection->hasMethod('getQueue')) |
|
48 | + { |
|
46 | 49 | return $reflection->getMethod('getQueue')->invoke($object); |
47 | 50 | } |
48 | 51 |
@@ -70,7 +70,8 @@ discard block |
||
70 | 70 | |
71 | 71 | public function getSecured(): mixed |
72 | 72 | { |
73 | - if ($this->getProperty('secured', true) === '*') { |
|
73 | + if ($this->getProperty('secured', true) === '*') |
|
74 | + { |
|
74 | 75 | return $this->getProperty('secured', true); |
75 | 76 | } |
76 | 77 | |
@@ -105,8 +106,10 @@ discard block |
||
105 | 106 | public function declaredMethods(): array |
106 | 107 | { |
107 | 108 | $methods = []; |
108 | - foreach ($this->getMethods() as $method) { |
|
109 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
109 | + foreach ($this->getMethods() as $method) |
|
110 | + { |
|
111 | + if ($method->getDeclaringClass()->getName() != $this->getName()) |
|
112 | + { |
|
110 | 113 | continue; |
111 | 114 | } |
112 | 115 | |
@@ -136,15 +139,18 @@ discard block |
||
136 | 139 | self::MUTATOR_ACCESSOR => [], |
137 | 140 | ]; |
138 | 141 | |
139 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
142 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter) |
|
143 | + { |
|
140 | 144 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
141 | 145 | } |
142 | 146 | |
143 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
147 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter) |
|
148 | + { |
|
144 | 149 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
145 | 150 | } |
146 | 151 | |
147 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
152 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter) |
|
153 | + { |
|
148 | 154 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
149 | 155 | } |
150 | 156 | |
@@ -160,7 +166,8 @@ discard block |
||
160 | 166 | */ |
161 | 167 | public function getProperty(string $property, bool $merge = false): mixed |
162 | 168 | { |
163 | - if (isset($this->propertyCache[$property])) { |
|
169 | + if (isset($this->propertyCache[$property])) |
|
170 | + { |
|
164 | 171 | //Property merging and trait events are pretty slow |
165 | 172 | return $this->propertyCache[$property]; |
166 | 173 | } |
@@ -168,27 +175,35 @@ discard block |
||
168 | 175 | $properties = $this->reflection->getDefaultProperties(); |
169 | 176 | $constants = $this->reflection->getConstants(); |
170 | 177 | |
171 | - if (isset($properties[$property])) { |
|
178 | + if (isset($properties[$property])) |
|
179 | + { |
|
172 | 180 | //Read from default value |
173 | 181 | $value = $properties[$property]; |
174 | - } elseif (isset($constants[\strtoupper($property)])) { |
|
182 | + } |
|
183 | + elseif (isset($constants[\strtoupper($property)])) |
|
184 | + { |
|
175 | 185 | //Read from a constant |
176 | 186 | $value = $constants[\strtoupper($property)]; |
177 | - } else { |
|
187 | + } |
|
188 | + else |
|
189 | + { |
|
178 | 190 | return null; |
179 | 191 | } |
180 | 192 | |
181 | 193 | //Merge with parent value requested |
182 | - if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) { |
|
194 | + if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) |
|
195 | + { |
|
183 | 196 | $parentValue = $parent->getProperty($property, $merge); |
184 | 197 | |
185 | - if (\is_array($parentValue)) { |
|
198 | + if (\is_array($parentValue)) |
|
199 | + { |
|
186 | 200 | //Class values prior to parent values |
187 | 201 | $value = \array_merge($parentValue, $value); |
188 | 202 | } |
189 | 203 | } |
190 | 204 | |
191 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
205 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)) |
|
206 | + { |
|
192 | 207 | return $value; |
193 | 208 | } |
194 | 209 | |
@@ -203,7 +218,8 @@ discard block |
||
203 | 218 | { |
204 | 219 | $parentClass = $this->reflection->getParentClass(); |
205 | 220 | |
206 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
221 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) |
|
222 | + { |
|
207 | 223 | $parent = clone $this; |
208 | 224 | $parent->reflection = $this->getParentClass(); |
209 | 225 |
@@ -49,8 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function has(string $name): bool |
51 | 51 | { |
52 | - foreach ($this->elements as $element) { |
|
53 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
52 | + foreach ($this->elements as $element) |
|
53 | + { |
|
54 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
55 | + { |
|
54 | 56 | return true; |
55 | 57 | } |
56 | 58 | } |
@@ -68,14 +70,17 @@ discard block |
||
68 | 70 | $reflector = new \ReflectionObject($element); |
69 | 71 | |
70 | 72 | $allowed = false; |
71 | - foreach ($this->allowed as $class) { |
|
72 | - if ($reflector->isSubclassOf($class) || $element::class === $class) { |
|
73 | + foreach ($this->allowed as $class) |
|
74 | + { |
|
75 | + if ($reflector->isSubclassOf($class) || $element::class === $class) |
|
76 | + { |
|
73 | 77 | $allowed = true; |
74 | 78 | break; |
75 | 79 | } |
76 | 80 | } |
77 | 81 | |
78 | - if (!$allowed) { |
|
82 | + if (!$allowed) |
|
83 | + { |
|
79 | 84 | $type = $element::class; |
80 | 85 | throw new ReactorException(\sprintf("Elements with type '%s' are not allowed", $type)); |
81 | 86 | } |
@@ -101,8 +106,10 @@ discard block |
||
101 | 106 | */ |
102 | 107 | public function remove(string $name): self |
103 | 108 | { |
104 | - foreach ($this->elements as $index => $element) { |
|
105 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
109 | + foreach ($this->elements as $index => $element) |
|
110 | + { |
|
111 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
112 | + { |
|
106 | 113 | unset($this->elements[$index]); |
107 | 114 | } |
108 | 115 | } |
@@ -152,8 +159,10 @@ discard block |
||
152 | 159 | */ |
153 | 160 | protected function find(string $name): AggregableInterface |
154 | 161 | { |
155 | - foreach ($this->elements as $element) { |
|
156 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
162 | + foreach ($this->elements as $element) |
|
163 | + { |
|
164 | + if ($element instanceof NamedInterface && $element->getName() === $name) |
|
165 | + { |
|
157 | 166 | return $element; |
158 | 167 | } |
159 | 168 | } |
@@ -31,14 +31,17 @@ discard block |
||
31 | 31 | string $action, |
32 | 32 | array $parameters = ['options' => null, 'payload' => []], |
33 | 33 | ): string { |
34 | - if ($parameters['options'] === null) { |
|
34 | + if ($parameters['options'] === null) |
|
35 | + { |
|
35 | 36 | $parameters['options'] = new Options(); |
36 | 37 | } |
37 | 38 | |
38 | 39 | $tracer = $this->getTracer(); |
39 | 40 | |
40 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
41 | - foreach ($tracer->getContext() as $key => $data) { |
|
41 | + if (\method_exists($parameters['options'], 'withHeader')) |
|
42 | + { |
|
43 | + foreach ($tracer->getContext() as $key => $data) |
|
44 | + { |
|
42 | 45 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
43 | 46 | } |
44 | 47 | } |
@@ -58,9 +61,12 @@ discard block |
||
58 | 61 | |
59 | 62 | private function getTracer(): TracerInterface |
60 | 63 | { |
61 | - try { |
|
64 | + try |
|
65 | + { |
|
62 | 66 | return ContainerScope::getContainer()->get(TracerInterface::class); |
63 | - } catch (\Throwable $e) { |
|
67 | + } |
|
68 | + catch (\Throwable $e) |
|
69 | + { |
|
64 | 70 | return new NullTracer(); |
65 | 71 | } |
66 | 72 | } |
@@ -66,17 +66,20 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
68 | 68 | { |
69 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
69 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
70 | + { |
|
70 | 71 | return $this->state->singletons[$alias]; |
71 | 72 | } |
72 | 73 | |
73 | 74 | $binding = $this->state->bindings[$alias] ?? null; |
74 | 75 | |
75 | - if ($binding === null) { |
|
76 | + if ($binding === null) |
|
77 | + { |
|
76 | 78 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
77 | 79 | } |
78 | 80 | |
79 | - try { |
|
81 | + try |
|
82 | + { |
|
80 | 83 | $this->tracer->push( |
81 | 84 | false, |
82 | 85 | action: 'resolve from binding', |
@@ -100,7 +103,9 @@ discard block |
||
100 | 103 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
101 | 104 | default => $binding, |
102 | 105 | }; |
103 | - } finally { |
|
106 | + } |
|
107 | + finally |
|
108 | + { |
|
104 | 109 | $this->state->bindings[$alias] ??= $binding; |
105 | 110 | $this->tracer->pop(true); |
106 | 111 | $this->tracer->pop(false); |
@@ -116,23 +121,29 @@ discard block |
||
116 | 121 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
117 | 122 | |
118 | 123 | // We have to construct class using external injector when we know exact context |
119 | - if ($arguments !== []) { |
|
124 | + if ($arguments !== []) |
|
125 | + { |
|
120 | 126 | // todo factory? |
121 | 127 | } |
122 | 128 | |
123 | 129 | $class = $ctx->class; |
124 | - try { |
|
130 | + try |
|
131 | + { |
|
125 | 132 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
126 | - } catch (\ReflectionException $e) { |
|
133 | + } |
|
134 | + catch (\ReflectionException $e) |
|
135 | + { |
|
127 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
128 | 137 | } |
129 | 138 | |
130 | 139 | $injector = $binding->injector; |
131 | 140 | |
132 | - try { |
|
141 | + try |
|
142 | + { |
|
133 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
134 | 144 | |
135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
146 | + { |
|
136 | 147 | throw new InjectionException( |
137 | 148 | \sprintf( |
138 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -146,7 +157,8 @@ discard block |
||
146 | 157 | * @psalm-suppress RedundantCondition |
147 | 158 | */ |
148 | 159 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
149 | - if (!$reflection->isInstance($instance)) { |
|
160 | + if (!$reflection->isInstance($instance)) |
|
161 | + { |
|
150 | 162 | throw new InjectionException( |
151 | 163 | \sprintf( |
152 | 164 | "Invalid injection response for '%s'.", |
@@ -156,7 +168,9 @@ discard block |
||
156 | 168 | } |
157 | 169 | |
158 | 170 | return $instance; |
159 | - } finally { |
|
171 | + } |
|
172 | + finally |
|
173 | + { |
|
160 | 174 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
161 | 175 | } |
162 | 176 | } |
@@ -175,7 +189,8 @@ discard block |
||
175 | 189 | //Binding is pointing to something else |
176 | 190 | : $this->make($binding->alias, $arguments, $context); |
177 | 191 | |
178 | - if ($binding->singleton && $arguments === []) { |
|
192 | + if ($binding->singleton && $arguments === []) |
|
193 | + { |
|
179 | 194 | $this->state->singletons[$alias] = $result; |
180 | 195 | } |
181 | 196 | |
@@ -216,11 +231,14 @@ discard block |
||
216 | 231 | array $arguments, |
217 | 232 | ): mixed { |
218 | 233 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
219 | - try { |
|
234 | + try |
|
235 | + { |
|
220 | 236 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
221 | 237 | ? ($binding->factory)() |
222 | 238 | : $this->invoker->invoke($binding->factory, $arguments); |
223 | - } catch (NotCallableException $e) { |
|
239 | + } |
|
240 | + catch (NotCallableException $e) |
|
241 | + { |
|
224 | 242 | throw new ContainerException( |
225 | 243 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
226 | 244 | $e->getCode(), |
@@ -239,19 +257,24 @@ discard block |
||
239 | 257 | ): ?object { |
240 | 258 | $avoidCache = $arguments !== []; |
241 | 259 | |
242 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
243 | - try { |
|
260 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
261 | + { |
|
262 | + try |
|
263 | + { |
|
244 | 264 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
245 | 265 | |
246 | 266 | $object = $this->createInstance( |
247 | 267 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
248 | 268 | $arguments, |
249 | 269 | ); |
250 | - if ($avoidCache) { |
|
270 | + if ($avoidCache) |
|
271 | + { |
|
251 | 272 | return $object; |
252 | 273 | } |
253 | 274 | $binding->reference = WeakReference::create($object); |
254 | - } catch (\Throwable) { |
|
275 | + } |
|
276 | + catch (\Throwable) |
|
277 | + { |
|
255 | 278 | throw new ContainerException( |
256 | 279 | $this->tracer->combineTraceMessage( |
257 | 280 | \sprintf( |
@@ -261,7 +284,9 @@ discard block |
||
261 | 284 | ) |
262 | 285 | ) |
263 | 286 | ); |
264 | - } finally { |
|
287 | + } |
|
288 | + finally |
|
289 | + { |
|
265 | 290 | $this->tracer->pop(); |
266 | 291 | } |
267 | 292 | } |
@@ -273,18 +298,25 @@ discard block |
||
273 | 298 | { |
274 | 299 | $parent = $this->scope->getParent(); |
275 | 300 | |
276 | - if ($parent !== null) { |
|
277 | - try { |
|
301 | + if ($parent !== null) |
|
302 | + { |
|
303 | + try |
|
304 | + { |
|
278 | 305 | $this->tracer->push(false, ...[ |
279 | 306 | 'current scope' => $this->scope->getScopeName(), |
280 | 307 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
281 | 308 | ]); |
282 | 309 | return $parent->make($alias, $parameters, $context); |
283 | - } catch (BadScopeException $e) { |
|
284 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
310 | + } |
|
311 | + catch (BadScopeException $e) |
|
312 | + { |
|
313 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
314 | + { |
|
285 | 315 | throw $e; |
286 | 316 | } |
287 | - } catch (ContainerExceptionInterface $e) { |
|
317 | + } |
|
318 | + catch (ContainerExceptionInterface $e) |
|
319 | + { |
|
288 | 320 | $className = match (true) { |
289 | 321 | $e instanceof NotFoundException => NotFoundException::class, |
290 | 322 | default => ContainerException::class, |
@@ -293,19 +325,24 @@ discard block |
||
293 | 325 | 'Can\'t resolve `%s`.', |
294 | 326 | $alias, |
295 | 327 | )), previous: $e); |
296 | - } finally { |
|
328 | + } |
|
329 | + finally |
|
330 | + { |
|
297 | 331 | $this->tracer->pop(false); |
298 | 332 | } |
299 | 333 | } |
300 | 334 | |
301 | 335 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
302 | - try { |
|
336 | + try |
|
337 | + { |
|
303 | 338 | //No direct instructions how to construct class, make is automatically |
304 | 339 | return $this->autowire( |
305 | 340 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
306 | 341 | $parameters, |
307 | 342 | ); |
308 | - } finally { |
|
343 | + } |
|
344 | + finally |
|
345 | + { |
|
309 | 346 | $this->tracer->pop(false); |
310 | 347 | } |
311 | 348 | } |
@@ -356,7 +393,8 @@ discard block |
||
356 | 393 | // Check scope name |
357 | 394 | $ctx->reflection = new \ReflectionClass($instance); |
358 | 395 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
359 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
396 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
397 | + { |
|
360 | 398 | throw new BadScopeException($scopeName, $instance::class); |
361 | 399 | } |
362 | 400 | |
@@ -383,24 +421,30 @@ discard block |
||
383 | 421 | array $parameters, |
384 | 422 | ): object { |
385 | 423 | $class = $ctx->class; |
386 | - try { |
|
424 | + try |
|
425 | + { |
|
387 | 426 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
388 | - } catch (\ReflectionException $e) { |
|
427 | + } |
|
428 | + catch (\ReflectionException $e) |
|
429 | + { |
|
389 | 430 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
390 | 431 | } |
391 | 432 | |
392 | 433 | // Check scope name |
393 | 434 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
394 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
435 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
436 | + { |
|
395 | 437 | throw new BadScopeException($scope, $class); |
396 | 438 | } |
397 | 439 | |
398 | 440 | //We have to construct class using external injector when we know exact context |
399 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
441 | + if ($parameters === [] && $this->binder->hasInjector($class)) |
|
442 | + { |
|
400 | 443 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
401 | 444 | } |
402 | 445 | |
403 | - if (!$reflection->isInstantiable()) { |
|
446 | + if (!$reflection->isInstantiable()) |
|
447 | + { |
|
404 | 448 | $itIs = match (true) { |
405 | 449 | $reflection->isEnum() => 'Enum', |
406 | 450 | $reflection->isAbstract() => 'Abstract class', |
@@ -413,12 +457,16 @@ discard block |
||
413 | 457 | |
414 | 458 | $constructor = $reflection->getConstructor(); |
415 | 459 | |
416 | - if ($constructor !== null) { |
|
417 | - try { |
|
460 | + if ($constructor !== null) |
|
461 | + { |
|
462 | + try |
|
463 | + { |
|
418 | 464 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
419 | 465 | $this->tracer->push(true); |
420 | 466 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
421 | - } catch (ValidationException $e) { |
|
467 | + } |
|
468 | + catch (ValidationException $e) |
|
469 | + { |
|
422 | 470 | throw new ContainerException( |
423 | 471 | $this->tracer->combineTraceMessage( |
424 | 472 | \sprintf( |
@@ -428,22 +476,31 @@ discard block |
||
428 | 476 | ) |
429 | 477 | ), |
430 | 478 | ); |
431 | - } finally { |
|
479 | + } |
|
480 | + finally |
|
481 | + { |
|
432 | 482 | $this->tracer->pop(true); |
433 | 483 | $this->tracer->pop(false); |
434 | 484 | } |
435 | - try { |
|
485 | + try |
|
486 | + { |
|
436 | 487 | // Using constructor with resolved arguments |
437 | 488 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
438 | 489 | $this->tracer->push(true); |
439 | 490 | $instance = new $class(...$arguments); |
440 | - } catch (\TypeError $e) { |
|
491 | + } |
|
492 | + catch (\TypeError $e) |
|
493 | + { |
|
441 | 494 | throw new WrongTypeException($constructor, $e); |
442 | - } finally { |
|
495 | + } |
|
496 | + finally |
|
497 | + { |
|
443 | 498 | $this->tracer->pop(true); |
444 | 499 | $this->tracer->pop(false); |
445 | 500 | } |
446 | - } else { |
|
501 | + } |
|
502 | + else |
|
503 | + { |
|
447 | 504 | // No constructor specified |
448 | 505 | $instance = $reflection->newInstance(); |
449 | 506 | } |
@@ -461,13 +518,15 @@ discard block |
||
461 | 518 | $instance = $this->runInflector($instance); |
462 | 519 | |
463 | 520 | //Declarative singletons |
464 | - if ($this->isSingleton($ctx)) { |
|
521 | + if ($this->isSingleton($ctx)) |
|
522 | + { |
|
465 | 523 | $this->state->singletons[$ctx->alias] = $instance; |
466 | 524 | } |
467 | 525 | |
468 | 526 | // Register finalizer |
469 | 527 | $finalizer = $this->getFinalizer($ctx, $instance); |
470 | - if ($finalizer !== null) { |
|
528 | + if ($finalizer !== null) |
|
529 | + { |
|
471 | 530 | $this->state->finalizers[] = $finalizer; |
472 | 531 | } |
473 | 532 | |
@@ -479,11 +538,13 @@ discard block |
||
479 | 538 | */ |
480 | 539 | private function isSingleton(Ctx $ctx): bool |
481 | 540 | { |
482 | - if ($ctx->singleton === true) { |
|
541 | + if ($ctx->singleton === true) |
|
542 | + { |
|
483 | 543 | return true; |
484 | 544 | } |
485 | 545 | |
486 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
546 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
547 | + { |
|
487 | 548 | return true; |
488 | 549 | } |
489 | 550 | |
@@ -497,7 +558,8 @@ discard block |
||
497 | 558 | * @var Finalize|null $attribute |
498 | 559 | */ |
499 | 560 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
500 | - if ($attribute === null) { |
|
561 | + if ($attribute === null) |
|
562 | + { |
|
501 | 563 | return null; |
502 | 564 | } |
503 | 565 | |
@@ -511,10 +573,14 @@ discard block |
||
511 | 573 | { |
512 | 574 | $scope = $this->scope; |
513 | 575 | |
514 | - while ($scope !== null) { |
|
515 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
516 | - if ($instance instanceof $class) { |
|
517 | - foreach ($inflectors as $inflector) { |
|
576 | + while ($scope !== null) |
|
577 | + { |
|
578 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
579 | + { |
|
580 | + if ($instance instanceof $class) |
|
581 | + { |
|
582 | + foreach ($inflectors as $inflector) |
|
583 | + { |
|
518 | 584 | $instance = $inflector->getParametersCount() > 1 |
519 | 585 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
520 | 586 | : ($inflector->inflector)($instance); |
@@ -15,16 +15,22 @@ discard block |
||
15 | 15 | |
16 | 16 | public function getEnums(object|string|null $target = null): array |
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)) |
|
19 | + { |
|
19 | 20 | $target = new \ReflectionClass($target); |
20 | 21 | } |
21 | 22 | |
22 | 23 | $result = []; |
23 | - foreach ($this->availableEnums() as $enum) { |
|
24 | - try { |
|
24 | + foreach ($this->availableEnums() as $enum) |
|
25 | + { |
|
26 | + try |
|
27 | + { |
|
25 | 28 | $reflection = $this->enumReflection($enum); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
29 | + } |
|
30 | + catch (LocatorException $e) |
|
31 | + { |
|
32 | + if ($this->debug) |
|
33 | + { |
|
28 | 34 | throw $e; |
29 | 35 | } |
30 | 36 | |
@@ -32,7 +38,8 @@ discard block |
||
32 | 38 | continue; |
33 | 39 | } |
34 | 40 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
41 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
42 | + { |
|
36 | 43 | continue; |
37 | 44 | } |
38 | 45 | |
@@ -51,7 +58,8 @@ discard block |
||
51 | 58 | { |
52 | 59 | $enums = []; |
53 | 60 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
61 | + foreach ($this->availableReflections() as $reflection) |
|
62 | + { |
|
55 | 63 | $enums = \array_merge($enums, $reflection->getEnums()); |
56 | 64 | } |
57 | 65 | |
@@ -65,11 +73,13 @@ discard block |
||
65 | 73 | */ |
66 | 74 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
67 | 75 | { |
68 | - if ($target === null) { |
|
76 | + if ($target === null) |
|
77 | + { |
|
69 | 78 | return true; |
70 | 79 | } |
71 | 80 | |
72 | - if (!$target->isTrait()) { |
|
81 | + if (!$target->isTrait()) |
|
82 | + { |
|
73 | 83 | //Target is interface or class |
74 | 84 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
75 | 85 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |