@@ -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 | } |
@@ -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); |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | declare(strict_types=1); |
| 4 | 4 | |
| 5 | -if (!\function_exists('inject')) { |
|
| 5 | +if (!\function_exists('inject')){ |
|
| 6 | 6 | /** |
| 7 | 7 | * Macro function to be replaced by the injected value. |
| 8 | 8 | */ |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | } |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -if (!\function_exists('injected')) { |
|
| 15 | +if (!\function_exists('injected')){ |
|
| 16 | 16 | /** |
| 17 | 17 | * Return true if block value has been defined. |
| 18 | 18 | * |
@@ -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 | return $enum->isSubclassOf($target) || $enum->getName() === $target->getName(); |
| 75 | 75 | } |