@@ -23,7 +23,7 @@ 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 | return true; |
28 | 28 | } |
29 | 29 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | $reflection = new \ReflectionClass($object); |
39 | 39 | |
40 | 40 | $attribute = $this->reader->firstClassMetadata($reflection, Queueable::class); |
41 | - if ($attribute !== null) { |
|
41 | + if ($attribute !== null){ |
|
42 | 42 | return $attribute->queue; |
43 | 43 | } |
44 | 44 | |
45 | - if (\is_object($object) && $reflection->hasMethod('getQueue')) { |
|
45 | + if (\is_object($object) && $reflection->hasMethod('getQueue')){ |
|
46 | 46 | return $reflection->getMethod('getQueue')->invoke($object); |
47 | 47 | } |
48 | 48 |
@@ -70,7 +70,7 @@ 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 | return $this->getProperty('secured', true); |
75 | 75 | } |
76 | 76 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | public function declaredMethods(): array |
106 | 106 | { |
107 | 107 | $methods = []; |
108 | - foreach ($this->getMethods() as $method) { |
|
109 | - if ($method->getDeclaringClass()->getName() != $this->getName()) { |
|
108 | + foreach ($this->getMethods() as $method){ |
|
109 | + if ($method->getDeclaringClass()->getName() != $this->getName()){ |
|
110 | 110 | continue; |
111 | 111 | } |
112 | 112 | |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | self::MUTATOR_ACCESSOR => [], |
137 | 137 | ]; |
138 | 138 | |
139 | - foreach ((array)$this->getProperty('getters', true) as $field => $filter) { |
|
139 | + foreach ((array)$this->getProperty('getters', true) as $field => $filter){ |
|
140 | 140 | $mutators[self::MUTATOR_GETTER][$field] = $filter; |
141 | 141 | } |
142 | 142 | |
143 | - foreach ((array)$this->getProperty('setters', true) as $field => $filter) { |
|
143 | + foreach ((array)$this->getProperty('setters', true) as $field => $filter){ |
|
144 | 144 | $mutators[self::MUTATOR_SETTER][$field] = $filter; |
145 | 145 | } |
146 | 146 | |
147 | - foreach ((array)$this->getProperty('accessors', true) as $field => $filter) { |
|
147 | + foreach ((array)$this->getProperty('accessors', true) as $field => $filter){ |
|
148 | 148 | $mutators[self::MUTATOR_ACCESSOR][$field] = $filter; |
149 | 149 | } |
150 | 150 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | public function getProperty(string $property, bool $merge = false): mixed |
162 | 162 | { |
163 | - if (isset($this->propertyCache[$property])) { |
|
163 | + if (isset($this->propertyCache[$property])){ |
|
164 | 164 | //Property merging and trait events are pretty slow |
165 | 165 | return $this->propertyCache[$property]; |
166 | 166 | } |
@@ -168,27 +168,27 @@ discard block |
||
168 | 168 | $properties = $this->reflection->getDefaultProperties(); |
169 | 169 | $constants = $this->reflection->getConstants(); |
170 | 170 | |
171 | - if (isset($properties[$property])) { |
|
171 | + if (isset($properties[$property])){ |
|
172 | 172 | //Read from default value |
173 | 173 | $value = $properties[$property]; |
174 | - } elseif (isset($constants[\strtoupper($property)])) { |
|
174 | + } elseif (isset($constants[\strtoupper($property)])){ |
|
175 | 175 | //Read from a constant |
176 | 176 | $value = $constants[\strtoupper($property)]; |
177 | - } else { |
|
177 | + }else{ |
|
178 | 178 | return null; |
179 | 179 | } |
180 | 180 | |
181 | 181 | //Merge with parent value requested |
182 | - if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())) { |
|
182 | + if ($merge && \is_array($value) && !empty($parent = $this->parentReflection())){ |
|
183 | 183 | $parentValue = $parent->getProperty($property, $merge); |
184 | 184 | |
185 | - if (\is_array($parentValue)) { |
|
185 | + if (\is_array($parentValue)){ |
|
186 | 186 | //Class values prior to parent values |
187 | 187 | $value = \array_merge($parentValue, $value); |
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - if (!$this->reflection->isSubclassOf(SchematicEntity::class)) { |
|
191 | + if (!$this->reflection->isSubclassOf(SchematicEntity::class)){ |
|
192 | 192 | return $value; |
193 | 193 | } |
194 | 194 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | { |
204 | 204 | $parentClass = $this->reflection->getParentClass(); |
205 | 205 | |
206 | - if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS) { |
|
206 | + if (!empty($parentClass) && $parentClass->getName() != static::BASE_CLASS){ |
|
207 | 207 | $parent = clone $this; |
208 | 208 | $parent->reflection = $this->getParentClass(); |
209 | 209 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public function __construct( |
21 | 21 | private array $allowed, |
22 | 22 | private array $elements = [] |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -49,8 +49,8 @@ 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 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
54 | 54 | return true; |
55 | 55 | } |
56 | 56 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | $reflector = new \ReflectionObject($element); |
69 | 69 | |
70 | 70 | $allowed = false; |
71 | - foreach ($this->allowed as $class) { |
|
72 | - if ($reflector->isSubclassOf($class) || $element::class === $class) { |
|
71 | + foreach ($this->allowed as $class){ |
|
72 | + if ($reflector->isSubclassOf($class) || $element::class === $class){ |
|
73 | 73 | $allowed = true; |
74 | 74 | break; |
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | - if (!$allowed) { |
|
78 | + if (!$allowed){ |
|
79 | 79 | $type = $element::class; |
80 | 80 | throw new ReactorException(\sprintf("Elements with type '%s' are not allowed", $type)); |
81 | 81 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function remove(string $name): self |
103 | 103 | { |
104 | - foreach ($this->elements as $index => $element) { |
|
105 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
104 | + foreach ($this->elements as $index => $element){ |
|
105 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
106 | 106 | unset($this->elements[$index]); |
107 | 107 | } |
108 | 108 | } |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function find(string $name): AggregableInterface |
154 | 154 | { |
155 | - foreach ($this->elements as $element) { |
|
156 | - if ($element instanceof NamedInterface && $element->getName() === $name) { |
|
155 | + foreach ($this->elements as $element){ |
|
156 | + if ($element instanceof NamedInterface && $element->getName() === $name){ |
|
157 | 157 | return $element; |
158 | 158 | } |
159 | 159 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | public function __construct( |
22 | 22 | private readonly QueueInterface $connection, |
23 | - ) { |
|
23 | + ){ |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -31,14 +31,14 @@ 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 | $parameters['options'] = new Options(); |
36 | 36 | } |
37 | 37 | |
38 | 38 | $tracer = $this->getTracer(); |
39 | 39 | |
40 | - if (\method_exists($parameters['options'], 'withHeader')) { |
|
41 | - foreach ($tracer->getContext() as $key => $data) { |
|
40 | + if (\method_exists($parameters['options'], 'withHeader')){ |
|
41 | + foreach ($tracer->getContext() as $key => $data){ |
|
42 | 42 | $parameters['options'] = $parameters['options']->withHeader($key, $data); |
43 | 43 | } |
44 | 44 | } |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | |
59 | 59 | private function getTracer(): TracerInterface |
60 | 60 | { |
61 | - try { |
|
61 | + try{ |
|
62 | 62 | return ContainerScope::getContainer()->get(TracerInterface::class); |
63 | - } catch (\Throwable $e) { |
|
63 | + }catch (\Throwable $e){ |
|
64 | 64 | return new NullTracer(); |
65 | 65 | } |
66 | 66 | } |
@@ -66,17 +66,17 @@ 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 | return $this->state->singletons[$alias]; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $binding = $this->state->bindings[$alias] ?? null; |
74 | 74 | |
75 | - if ($binding === null) { |
|
75 | + if ($binding === null){ |
|
76 | 76 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
77 | 77 | } |
78 | 78 | |
79 | - try { |
|
79 | + try{ |
|
80 | 80 | $this->tracer->push( |
81 | 81 | false, |
82 | 82 | action: 'resolve from binding', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
101 | 101 | default => $binding, |
102 | 102 | }; |
103 | - } finally { |
|
103 | + }finally{ |
|
104 | 104 | $this->state->bindings[$alias] ??= $binding; |
105 | 105 | $this->tracer->pop(true); |
106 | 106 | $this->tracer->pop(false); |
@@ -112,27 +112,27 @@ discard block |
||
112 | 112 | string $alias, |
113 | 113 | ?string $context, |
114 | 114 | array $arguments, |
115 | - ) { |
|
116 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
|
115 | + ){ |
|
116 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context); |
|
117 | 117 | |
118 | 118 | // We have to construct class using external injector when we know exact context |
119 | - if ($arguments !== []) { |
|
119 | + if ($arguments !== []){ |
|
120 | 120 | // todo factory? |
121 | 121 | } |
122 | 122 | |
123 | 123 | $class = $ctx->class; |
124 | - try { |
|
124 | + try{ |
|
125 | 125 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
126 | - } catch (\ReflectionException $e) { |
|
126 | + }catch (\ReflectionException $e){ |
|
127 | 127 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
128 | 128 | } |
129 | 129 | |
130 | 130 | $injector = $binding->injector; |
131 | 131 | |
132 | - try { |
|
132 | + try{ |
|
133 | 133 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
134 | 134 | |
135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
135 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
136 | 136 | throw new InjectionException( |
137 | 137 | \sprintf( |
138 | 138 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @psalm-suppress RedundantCondition |
147 | 147 | */ |
148 | 148 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
149 | - if (!$reflection->isInstance($instance)) { |
|
149 | + if (!$reflection->isInstance($instance)){ |
|
150 | 150 | throw new InjectionException( |
151 | 151 | \sprintf( |
152 | 152 | "Invalid injection response for '%s'.", |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | return $instance; |
159 | - } finally { |
|
159 | + }finally{ |
|
160 | 160 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
161 | 161 | } |
162 | 162 | } |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | ): mixed { |
170 | 170 | $result = $binding->alias === $alias |
171 | 171 | ? $this->autowire( |
172 | - new Ctx(alias: $alias, class: $binding->alias, parameter: $context, singleton: $binding->singleton), |
|
172 | + new Ctx(alias : $alias, class : $binding->alias, parameter : $context, singleton : $binding->singleton), |
|
173 | 173 | $arguments, |
174 | 174 | ) |
175 | 175 | //Binding is pointing to something else |
176 | 176 | : $this->make($binding->alias, $arguments, $context); |
177 | 177 | |
178 | - if ($binding->singleton && $arguments === []) { |
|
178 | + if ($binding->singleton && $arguments === []){ |
|
179 | 179 | $this->state->singletons[$alias] = $result; |
180 | 180 | } |
181 | 181 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $avoidCache = $arguments !== []; |
192 | 192 | return $avoidCache |
193 | 193 | ? $this->createInstance( |
194 | - new Ctx(alias: $alias, class: $binding->value::class, parameter: $context), |
|
194 | + new Ctx(alias : $alias, class : $binding->value::class, parameter : $context), |
|
195 | 195 | $arguments, |
196 | 196 | ) |
197 | 197 | : $binding->value; |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | private function resolveFactory( |
213 | - \Spiral\Core\Config\Factory|DeferredFactory $binding, |
|
213 | + \Spiral\Core\Config\Factory | DeferredFactory $binding, |
|
214 | 214 | string $alias, |
215 | 215 | ?string $context, |
216 | 216 | array $arguments, |
217 | 217 | ): mixed { |
218 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
|
219 | - try { |
|
218 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context, singleton : $binding->singleton); |
|
219 | + try{ |
|
220 | 220 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
221 | 221 | ? ($binding->factory)() |
222 | 222 | : $this->invoker->invoke($binding->factory, $arguments); |
223 | - } catch (NotCallableException $e) { |
|
223 | + }catch (NotCallableException $e){ |
|
224 | 224 | throw new ContainerException( |
225 | 225 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
226 | 226 | $e->getCode(), |
@@ -239,19 +239,19 @@ discard block |
||
239 | 239 | ): ?object { |
240 | 240 | $avoidCache = $arguments !== []; |
241 | 241 | |
242 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
243 | - try { |
|
242 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
243 | + try{ |
|
244 | 244 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
245 | 245 | |
246 | 246 | $object = $this->createInstance( |
247 | 247 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
248 | 248 | $arguments, |
249 | 249 | ); |
250 | - if ($avoidCache) { |
|
250 | + if ($avoidCache){ |
|
251 | 251 | return $object; |
252 | 252 | } |
253 | 253 | $binding->reference = WeakReference::create($object); |
254 | - } catch (\Throwable) { |
|
254 | + }catch (\Throwable){ |
|
255 | 255 | throw new ContainerException( |
256 | 256 | $this->tracer->combineTraceMessage( |
257 | 257 | \sprintf( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ) |
262 | 262 | ) |
263 | 263 | ); |
264 | - } finally { |
|
264 | + }finally{ |
|
265 | 265 | $this->tracer->pop(); |
266 | 266 | } |
267 | 267 | } |
@@ -273,18 +273,18 @@ discard block |
||
273 | 273 | { |
274 | 274 | $parent = $this->scope->getParent(); |
275 | 275 | |
276 | - if ($parent !== null) { |
|
277 | - try { |
|
276 | + if ($parent !== null){ |
|
277 | + try{ |
|
278 | 278 | $this->tracer->push(false, ...[ |
279 | 279 | 'current scope' => $this->scope->getScopeName(), |
280 | 280 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
281 | 281 | ]); |
282 | 282 | return $parent->make($alias, $parameters, $context); |
283 | - } catch (BadScopeException $e) { |
|
284 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
283 | + }catch (BadScopeException $e){ |
|
284 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
285 | 285 | throw $e; |
286 | 286 | } |
287 | - } catch (ContainerExceptionInterface $e) { |
|
287 | + }catch (ContainerExceptionInterface $e){ |
|
288 | 288 | $className = match (true) { |
289 | 289 | $e instanceof NotFoundException => NotFoundException::class, |
290 | 290 | default => ContainerException::class, |
@@ -293,19 +293,19 @@ discard block |
||
293 | 293 | 'Can\'t resolve `%s`.', |
294 | 294 | $alias, |
295 | 295 | )), previous: $e); |
296 | - } finally { |
|
296 | + }finally{ |
|
297 | 297 | $this->tracer->pop(false); |
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | 301 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
302 | - try { |
|
302 | + try{ |
|
303 | 303 | //No direct instructions how to construct class, make is automatically |
304 | 304 | return $this->autowire( |
305 | 305 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
306 | 306 | $parameters, |
307 | 307 | ); |
308 | - } finally { |
|
308 | + }finally{ |
|
309 | 309 | $this->tracer->pop(false); |
310 | 310 | } |
311 | 311 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | && |
328 | 328 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
329 | 329 | )) |
330 | - ) { |
|
330 | + ){ |
|
331 | 331 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
332 | 332 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
333 | 333 | $this->tracer->getRootAlias(), |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | // Check scope name |
357 | 357 | $ctx->reflection = new \ReflectionClass($instance); |
358 | 358 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
359 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
359 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
360 | 360 | throw new BadScopeException($scopeName, $instance::class); |
361 | 361 | } |
362 | 362 | |
@@ -383,24 +383,24 @@ discard block |
||
383 | 383 | array $parameters, |
384 | 384 | ): object { |
385 | 385 | $class = $ctx->class; |
386 | - try { |
|
386 | + try{ |
|
387 | 387 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
388 | - } catch (\ReflectionException $e) { |
|
388 | + }catch (\ReflectionException $e){ |
|
389 | 389 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
390 | 390 | } |
391 | 391 | |
392 | 392 | // Check scope name |
393 | 393 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
394 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
394 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
395 | 395 | throw new BadScopeException($scope, $class); |
396 | 396 | } |
397 | 397 | |
398 | 398 | //We have to construct class using external injector when we know exact context |
399 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
399 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
400 | 400 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
401 | 401 | } |
402 | 402 | |
403 | - if (!$reflection->isInstantiable()) { |
|
403 | + if (!$reflection->isInstantiable()){ |
|
404 | 404 | $itIs = match (true) { |
405 | 405 | $reflection->isEnum() => 'Enum', |
406 | 406 | $reflection->isAbstract() => 'Abstract class', |
@@ -413,12 +413,12 @@ discard block |
||
413 | 413 | |
414 | 414 | $constructor = $reflection->getConstructor(); |
415 | 415 | |
416 | - if ($constructor !== null) { |
|
417 | - try { |
|
416 | + if ($constructor !== null){ |
|
417 | + try{ |
|
418 | 418 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
419 | 419 | $this->tracer->push(true); |
420 | 420 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
421 | - } catch (ValidationException $e) { |
|
421 | + }catch (ValidationException $e){ |
|
422 | 422 | throw new ContainerException( |
423 | 423 | $this->tracer->combineTraceMessage( |
424 | 424 | \sprintf( |
@@ -428,22 +428,22 @@ discard block |
||
428 | 428 | ) |
429 | 429 | ), |
430 | 430 | ); |
431 | - } finally { |
|
431 | + }finally{ |
|
432 | 432 | $this->tracer->pop(true); |
433 | 433 | $this->tracer->pop(false); |
434 | 434 | } |
435 | - try { |
|
435 | + try{ |
|
436 | 436 | // Using constructor with resolved arguments |
437 | 437 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
438 | 438 | $this->tracer->push(true); |
439 | 439 | $instance = new $class(...$arguments); |
440 | - } catch (\TypeError $e) { |
|
440 | + }catch (\TypeError $e){ |
|
441 | 441 | throw new WrongTypeException($constructor, $e); |
442 | - } finally { |
|
442 | + }finally{ |
|
443 | 443 | $this->tracer->pop(true); |
444 | 444 | $this->tracer->pop(false); |
445 | 445 | } |
446 | - } else { |
|
446 | + }else{ |
|
447 | 447 | // No constructor specified |
448 | 448 | $instance = $reflection->newInstance(); |
449 | 449 | } |
@@ -461,13 +461,13 @@ discard block |
||
461 | 461 | $instance = $this->runInflector($instance); |
462 | 462 | |
463 | 463 | //Declarative singletons |
464 | - if ($this->isSingleton($ctx)) { |
|
464 | + if ($this->isSingleton($ctx)){ |
|
465 | 465 | $this->state->singletons[$ctx->alias] = $instance; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Register finalizer |
469 | 469 | $finalizer = $this->getFinalizer($ctx, $instance); |
470 | - if ($finalizer !== null) { |
|
470 | + if ($finalizer !== null){ |
|
471 | 471 | $this->state->finalizers[] = $finalizer; |
472 | 472 | } |
473 | 473 | |
@@ -479,11 +479,11 @@ discard block |
||
479 | 479 | */ |
480 | 480 | private function isSingleton(Ctx $ctx): bool |
481 | 481 | { |
482 | - if ($ctx->singleton === true) { |
|
482 | + if ($ctx->singleton === true){ |
|
483 | 483 | return true; |
484 | 484 | } |
485 | 485 | |
486 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
486 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
487 | 487 | return true; |
488 | 488 | } |
489 | 489 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @var Finalize|null $attribute |
498 | 498 | */ |
499 | 499 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
500 | - if ($attribute === null) { |
|
500 | + if ($attribute === null){ |
|
501 | 501 | return null; |
502 | 502 | } |
503 | 503 | |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | { |
512 | 512 | $scope = $this->scope; |
513 | 513 | |
514 | - while ($scope !== null) { |
|
515 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
516 | - if ($instance instanceof $class) { |
|
517 | - foreach ($inflectors as $inflector) { |
|
514 | + while ($scope !== null){ |
|
515 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
516 | + if ($instance instanceof $class){ |
|
517 | + foreach ($inflectors as $inflector){ |
|
518 | 518 | $instance = $inflector->getParametersCount() > 1 |
519 | 519 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
520 | 520 | : ($inflector->inflector)($instance); |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
50 | 50 | |
51 | 51 | private Internal\State $state; |
52 | - private ResolverInterface|Internal\Resolver $resolver; |
|
53 | - private FactoryInterface|Internal\Factory $factory; |
|
54 | - private ContainerInterface|Internal\Container $container; |
|
55 | - private BinderInterface|Internal\Binder $binder; |
|
56 | - private InvokerInterface|Internal\Invoker $invoker; |
|
52 | + private ResolverInterface | Internal\Resolver $resolver; |
|
53 | + private FactoryInterface | Internal\Factory $factory; |
|
54 | + private ContainerInterface | Internal\Container $container; |
|
55 | + private BinderInterface | Internal\Binder $binder; |
|
56 | + private InvokerInterface | Internal\Invoker $invoker; |
|
57 | 57 | private Internal\Scope $scope; |
58 | 58 | |
59 | 59 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function __construct( |
63 | 63 | private Config $config = new Config(), |
64 | 64 | ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
65 | - ) { |
|
65 | + ){ |
|
66 | 66 | $this->initServices($this, $scopeName); |
67 | 67 | |
68 | 68 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @throws ContainerException |
139 | 139 | * @throws \Throwable |
140 | 140 | */ |
141 | - public function get(string|Autowire $id, string $context = null): mixed |
|
141 | + public function get(string | Autowire $id, string $context = null): mixed |
|
142 | 142 | { |
143 | 143 | /** @psalm-suppress TooManyArguments */ |
144 | 144 | return $this->container->get($id, $context); |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | $binds = &$this->state->bindings; |
167 | 167 | $singletons = &$this->state->singletons; |
168 | 168 | $cleanup = $previous = $prevSin = []; |
169 | - foreach ($bindings as $alias => $resolver) { |
|
169 | + foreach ($bindings as $alias => $resolver){ |
|
170 | 170 | // Store previous bindings |
171 | - if (isset($binds[$alias])) { |
|
171 | + if (isset($binds[$alias])){ |
|
172 | 172 | $previous[$alias] = $binds[$alias]; |
173 | - } else { |
|
173 | + }else{ |
|
174 | 174 | // Store bindings to be removed |
175 | 175 | $cleanup[] = $alias; |
176 | 176 | } |
177 | 177 | // Store previous singletons |
178 | - if (isset($singletons[$alias])) { |
|
178 | + if (isset($singletons[$alias])){ |
|
179 | 179 | $prevSin[$alias] = $singletons[$alias]; |
180 | 180 | unset($singletons[$alias]); |
181 | 181 | } |
@@ -183,21 +183,21 @@ discard block |
||
183 | 183 | $this->binder->bind($alias, $resolver); |
184 | 184 | } |
185 | 185 | |
186 | - try { |
|
186 | + try{ |
|
187 | 187 | return ContainerScope::getContainer() !== $this |
188 | 188 | ? ContainerScope::runScope($this, $scope) |
189 | 189 | : $scope($this); |
190 | - } finally { |
|
190 | + }finally{ |
|
191 | 191 | // Remove new bindings |
192 | - foreach ($cleanup as $alias) { |
|
192 | + foreach ($cleanup as $alias){ |
|
193 | 193 | unset($binds[$alias], $singletons[$alias]); |
194 | 194 | } |
195 | 195 | // Restore previous bindings |
196 | - foreach ($previous as $alias => $resolver) { |
|
196 | + foreach ($previous as $alias => $resolver){ |
|
197 | 197 | $binds[$alias] = $resolver; |
198 | 198 | } |
199 | 199 | // Restore singletons |
200 | - foreach ($prevSin as $alias => $instance) { |
|
200 | + foreach ($prevSin as $alias => $instance){ |
|
201 | 201 | $singletons[$alias] = $instance; |
202 | 202 | } |
203 | 203 | } |
@@ -211,32 +211,32 @@ discard block |
||
211 | 211 | // Open scope |
212 | 212 | $container = new self($this->config, $name); |
213 | 213 | |
214 | - try { |
|
214 | + try{ |
|
215 | 215 | // Configure scope |
216 | 216 | $container->scope->setParent($this, $this->scope); |
217 | 217 | |
218 | 218 | // Add specific bindings |
219 | - foreach ($bindings as $alias => $resolver) { |
|
219 | + foreach ($bindings as $alias => $resolver){ |
|
220 | 220 | $container->binder->bind($alias, $resolver); |
221 | 221 | } |
222 | 222 | |
223 | 223 | return ContainerScope::runScope( |
224 | 224 | $container, |
225 | 225 | static function (self $container) use ($autowire, $closure): mixed { |
226 | - try { |
|
226 | + try{ |
|
227 | 227 | return $autowire |
228 | 228 | ? $container->invoke($closure) |
229 | 229 | : $closure($container); |
230 | - } finally { |
|
230 | + }finally{ |
|
231 | 231 | $container->closeScope(); |
232 | 232 | } |
233 | 233 | } |
234 | 234 | ); |
235 | - } finally { |
|
235 | + }finally{ |
|
236 | 236 | // Check the container has not been leaked |
237 | 237 | $link = \WeakReference::create($container); |
238 | 238 | unset($container); |
239 | - if ($link->get() !== null) { |
|
239 | + if ($link->get() !== null){ |
|
240 | 240 | throw new ScopeContainerLeakedException($name, $this->scope->getParentScopeNames()); |
241 | 241 | } |
242 | 242 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @psalm-param TResolver $resolver |
270 | 270 | */ |
271 | - public function bindSingleton(string $alias, string|array|callable|object $resolver): void |
|
271 | + public function bindSingleton(string $alias, string | array | callable | object $resolver): void |
|
272 | 272 | { |
273 | 273 | $this->binder->bindSingleton($alias, $resolver); |
274 | 274 | } |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | ]); |
336 | 336 | |
337 | 337 | // Create container services |
338 | - foreach ($container->config as $property => $class) { |
|
339 | - if (\property_exists($container, $property)) { |
|
338 | + foreach ($container->config as $property => $class){ |
|
339 | + if (\property_exists($container, $property)){ |
|
340 | 340 | $container->$property = $constructor->get($property, $class); |
341 | 341 | } |
342 | 342 | } |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | private function closeScope(): void |
351 | 351 | { |
352 | 352 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
353 | - if (!isset($this->scope)) { |
|
353 | + if (!isset($this->scope)){ |
|
354 | 354 | $this->destruct(); |
355 | 355 | return; |
356 | 356 | } |
@@ -359,10 +359,10 @@ discard block |
||
359 | 359 | |
360 | 360 | // Run finalizers |
361 | 361 | $errors = []; |
362 | - foreach ($this->state->finalizers as $finalizer) { |
|
363 | - try { |
|
362 | + foreach ($this->state->finalizers as $finalizer){ |
|
363 | + try{ |
|
364 | 364 | $this->invoker->invoke($finalizer); |
365 | - } catch (\Throwable $e) { |
|
365 | + }catch (\Throwable $e){ |
|
366 | 366 | $errors[] = $e; |
367 | 367 | } |
368 | 368 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $this->destruct(); |
372 | 372 | |
373 | 373 | // Throw collected errors |
374 | - if ($errors !== []) { |
|
374 | + if ($errors !== []){ |
|
375 | 375 | throw new FinalizersException($scopeName, $errors); |
376 | 376 | } |
377 | 377 | } |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | { |
14 | 14 | public const INJECTOR = EnumLocatorInjector::class; |
15 | 15 | |
16 | - public function getEnums(object|string|null $target = null): array |
|
16 | + public function getEnums(object | string | null $target = null): array |
|
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)){ |
|
19 | 19 | $target = new \ReflectionClass($target); |
20 | 20 | } |
21 | 21 | |
22 | 22 | $result = []; |
23 | - foreach ($this->availableEnums() as $enum) { |
|
24 | - try { |
|
23 | + foreach ($this->availableEnums() as $enum){ |
|
24 | + try{ |
|
25 | 25 | $reflection = $this->enumReflection($enum); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
26 | + }catch (LocatorException $e){ |
|
27 | + if ($this->debug){ |
|
28 | 28 | throw $e; |
29 | 29 | } |
30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
35 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $enums = []; |
53 | 53 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | + foreach ($this->availableReflections() as $reflection){ |
|
55 | 55 | $enums = \array_merge($enums, $reflection->getEnums()); |
56 | 56 | } |
57 | 57 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
67 | 67 | { |
68 | - if ($target === null) { |
|
68 | + if ($target === null){ |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | |
72 | - if (!$target->isTrait()) { |
|
72 | + if (!$target->isTrait()){ |
|
73 | 73 | //Target is interface or class |
74 | 74 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
75 | 75 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |