@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | context: Parameter #1 [ <required> Spiral\Tests\Core\Fixtures\InvalidClass $class ] |
| 209 | 209 | MARKDOWN; |
| 210 | 210 | |
| 211 | - try { |
|
| 211 | + try{ |
|
| 212 | 212 | $container->get(InvalidWithContainerInside::class); |
| 213 | 213 | self::fail('Exception `ContainerException` expected'); |
| 214 | - } catch (ContainerException $e) { |
|
| 214 | + }catch (ContainerException $e){ |
|
| 215 | 215 | self::assertSame($expectedMessage, $e->getMessage()); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $container = new Container(); |
| 236 | 236 | |
| 237 | - try { |
|
| 237 | + try{ |
|
| 238 | 238 | $container->get('invalid'); |
| 239 | - } catch (ContainerException $e) { |
|
| 239 | + }catch (ContainerException $e){ |
|
| 240 | 240 | self::assertSame(<<<MARKDOWN |
| 241 | 241 | Can't autowire `invalid`: class or injector not found. |
| 242 | 242 | Resolving trace: |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | { |
| 268 | 268 | $this->expectException(ContainerException::class); |
| 269 | 269 | |
| 270 | - try { |
|
| 270 | + try{ |
|
| 271 | 271 | $container->get(ClassWithUndefinedDependency::class); |
| 272 | - } catch (ContainerException $e) { |
|
| 272 | + }catch (ContainerException $e){ |
|
| 273 | 273 | self::assertSame($message, $e->getMessage()); |
| 274 | 274 | |
| 275 | 275 | throw $e; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $root = self::makeContainer(); |
| 168 | 168 | |
| 169 | - try { |
|
| 169 | + try{ |
|
| 170 | 170 | $root->runScoped(static function (Container $c1): void { |
| 171 | 171 | $c1->runScoped(static function (Container $c2): void { |
| 172 | 172 | $c2->runScoped(static function (Container $c3): void { |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | }, name: 'root'); |
| 175 | 175 | }); |
| 176 | 176 | }); |
| 177 | - } catch (NamedScopeDuplicationException $e) { |
|
| 177 | + }catch (NamedScopeDuplicationException $e){ |
|
| 178 | 178 | self::assertSame('root', $e->getScope()); |
| 179 | 179 | throw $e; |
| 180 | 180 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | #[Group('scrutinizer-ignore')] |
| 188 | 188 | public function testBadScopeException(): void |
| 189 | 189 | { |
| 190 | - try { |
|
| 190 | + try{ |
|
| 191 | 191 | $root = self::makeContainer(); |
| 192 | 192 | $root->runScoped(static function (Container $c1): void { |
| 193 | 193 | $c1->runScoped(static function (Container $c2): void { |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | }); |
| 196 | 196 | }, name: 'bar'); |
| 197 | 197 | |
| 198 | - self::fail(BadScopeException::class . ' should be thrown'); |
|
| 199 | - } catch (BadScopeException $e) { |
|
| 198 | + self::fail(BadScopeException::class.' should be thrown'); |
|
| 199 | + }catch (BadScopeException $e){ |
|
| 200 | 200 | self::assertSame('foo', $e->getScope()); |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | |
| 7 | 7 | final class PrivateConstructor |
| 8 | 8 | { |
| 9 | - private function __construct() {} |
|
| 9 | + private function __construct(){} |
|
| 10 | 10 | |
| 11 | 11 | private static function privateMethod(int $result): int |
| 12 | 12 | { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $this->container->bindSingleton(Bucket::class, $bucket = new Bucket('foo')); |
| 74 | 74 | |
| 75 | - $result = $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']); |
|
| 75 | + $result = $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']); |
|
| 76 | 76 | |
| 77 | 77 | self::assertSame($bucket, $result['bucket']); |
| 78 | 78 | self::assertInstanceOf(SampleClass::class, $result['class']); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | public function testCallStaticMethodWithoutInstantiationWithOvertypedFactory(): void |
| 151 | 151 | { |
| 152 | - $this->container->bind('foo', fn(): PrivateConstructor|SampleClass => throw new \Exception('Factory called')); |
|
| 152 | + $this->container->bind('foo', fn(): PrivateConstructor | SampleClass => throw new \Exception('Factory called')); |
|
| 153 | 153 | $this->expectExceptionMessage('Factory called'); |
| 154 | 154 | $this->container->invoke(['foo', 'publicMethod'], [42]); |
| 155 | 155 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $this->expectException(ArgumentResolvingException::class); |
| 170 | 170 | $this->expectExceptionMessage('Unable to resolve required argument `name` when resolving'); |
| 171 | 171 | |
| 172 | - $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']); |
|
| 172 | + $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | public function testCallValidClosure(): void |
@@ -37,23 +37,23 @@ discard block |
||
| 37 | 37 | public function make( |
| 38 | 38 | string $alias, |
| 39 | 39 | array $parameters = [], |
| 40 | - \Stringable|string|null $context = null, |
|
| 40 | + \Stringable | string | null $context = null, |
|
| 41 | 41 | ?Tracer $tracer = null, |
| 42 | 42 | ): mixed { |
| 43 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 43 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
| 44 | 44 | return $this->state->singletons[$alias]; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | $this->actor->resolveType($alias, $binding, $singleton, $injector, $actor, false); |
| 49 | - if ($parameters === [] && $singleton !== null) { |
|
| 49 | + if ($parameters === [] && $singleton !== null){ |
|
| 50 | 50 | return $singleton; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $tracer ??= new Tracer(); |
| 54 | 54 | |
| 55 | 55 | // Resolve without binding |
| 56 | - if ($binding === null) { |
|
| 56 | + if ($binding === null){ |
|
| 57 | 57 | $tracer->push( |
| 58 | 58 | false, |
| 59 | 59 | action: 'autowire', |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | scope: $this->scope->getScopeName(), |
| 62 | 62 | context: $context, |
| 63 | 63 | ); |
| 64 | - try { |
|
| 64 | + try{ |
|
| 65 | 65 | // No direct instructions how to construct class, make is automatically |
| 66 | 66 | return $this->actor->autowire( |
| 67 | 67 | new Ctx(alias: $alias, class: $alias, context: $context, singleton: $parameters === [] ? null : false), |
@@ -69,12 +69,12 @@ discard block |
||
| 69 | 69 | $actor, |
| 70 | 70 | $tracer, |
| 71 | 71 | ); |
| 72 | - } finally { |
|
| 72 | + }finally{ |
|
| 73 | 73 | $tracer->pop(false); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - try { |
|
| 77 | + try{ |
|
| 78 | 78 | $tracer->push( |
| 79 | 79 | false, |
| 80 | 80 | action: 'resolve from binding', |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | // unset($this->state->bindings[$alias]); |
| 89 | 89 | return $actor->resolveBinding($binding, $alias, $context, $parameters, $tracer); |
| 90 | - } finally { |
|
| 90 | + }finally{ |
|
| 91 | 91 | // $this->state->bindings[$alias] ??= $binding; |
| 92 | 92 | $tracer->pop(true); |
| 93 | 93 | $tracer->pop(false); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct( |
| 19 | 19 | private readonly ?string $scopeName = null, |
| 20 | - ) {} |
|
| 20 | + ){} |
|
| 21 | 21 | |
| 22 | 22 | public function getScopeName(): ?string |
| 23 | 23 | { |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | $this->parentActor = $actor; |
| 40 | 40 | |
| 41 | 41 | // Check a scope with the same name is not already registered |
| 42 | - if ($this->scopeName !== null) { |
|
| 42 | + if ($this->scopeName !== null){ |
|
| 43 | 43 | $tmp = $this; |
| 44 | - while ($tmp->parentScope !== null) { |
|
| 44 | + while ($tmp->parentScope !== null){ |
|
| 45 | 45 | $tmp = $tmp->parentScope; |
| 46 | 46 | $tmp->scopeName !== $this->scopeName ?: throw new NamedScopeDuplicationException($this->scopeName); |
| 47 | 47 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $result = [$this->scopeName]; |
| 65 | 65 | |
| 66 | 66 | $parent = $this; |
| 67 | - while ($parent->parentScope !== null) { |
|
| 67 | + while ($parent->parentScope !== null){ |
|
| 68 | 68 | $parent = $parent->parentScope; |
| 69 | 69 | $result[] = $parent->scopeName; |
| 70 | 70 | } |
@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function invoke(mixed $target, array $parameters = []): mixed |
| 44 | 44 | { |
| 45 | - if (\is_array($target) && isset($target[1])) { |
|
| 45 | + if (\is_array($target) && isset($target[1])){ |
|
| 46 | 46 | // In a form of resolver and method |
| 47 | 47 | [$resolver, $method] = $target; |
| 48 | 48 | |
| 49 | 49 | // Resolver instance or class name if the method is static (i.e. [ClassName::class, 'method']) |
| 50 | - if (\is_string($resolver)) { |
|
| 50 | + if (\is_string($resolver)){ |
|
| 51 | 51 | // Detect return type |
| 52 | 52 | $type = $this->actor->resolveType($resolver, $binding, $singleton, $injector); |
| 53 | 53 | |
| 54 | - if ($singleton === null) { |
|
| 54 | + if ($singleton === null){ |
|
| 55 | 55 | $type ??= $injector === null && $binding === null ? $resolver : null; |
| 56 | 56 | $resolver = \is_callable([$type, $method]) ? $type : $this->container->get($resolver); |
| 57 | - } else { |
|
| 57 | + }else{ |
|
| 58 | 58 | $resolver = $singleton; |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - try { |
|
| 62 | + try{ |
|
| 63 | 63 | $method = new \ReflectionMethod($resolver, $method); |
| 64 | - } catch (\ReflectionException $e) { |
|
| 64 | + }catch (\ReflectionException $e){ |
|
| 65 | 65 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if (\is_string($target) && \is_callable($target)) { |
|
| 75 | + if (\is_string($target) && \is_callable($target)){ |
|
| 76 | 76 | $target = $target(...); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ($target instanceof \Closure) { |
|
| 80 | - try { |
|
| 79 | + if ($target instanceof \Closure){ |
|
| 80 | + try{ |
|
| 81 | 81 | $reflection = new \ReflectionFunction($target); |
| 82 | - } catch (\ReflectionException $e) { |
|
| 82 | + }catch (\ReflectionException $e){ |
|
| 83 | 83 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function resolveType( |
| 78 | 78 | string $alias, |
| 79 | - ?Binding &$binding = null, |
|
| 79 | + ?Binding & $binding = null, |
|
| 80 | 80 | ?object &$singleton = null, |
| 81 | 81 | ?object &$injector = null, |
| 82 | 82 | ?self &$actor = null, |
@@ -85,21 +85,21 @@ discard block |
||
| 85 | 85 | // Aliases to prevent circular dependencies |
| 86 | 86 | $as = []; |
| 87 | 87 | $actor = $this; |
| 88 | - do { |
|
| 88 | + do{ |
|
| 89 | 89 | $bindings = &$actor->state->bindings; |
| 90 | 90 | $singletons = &$actor->state->singletons; |
| 91 | 91 | $injectors = &$actor->state->injectors; |
| 92 | - if (\array_key_exists($alias, $singletons)) { |
|
| 92 | + if (\array_key_exists($alias, $singletons)){ |
|
| 93 | 93 | $singleton = $singletons[$alias]; |
| 94 | 94 | $binding = $bindings[$alias] ?? null; |
| 95 | 95 | $injector = $injectors[$alias] ?? null; |
| 96 | 96 | return \is_object($singleton::class) ? $singleton::class : null; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if (\array_key_exists($alias, $bindings)) { |
|
| 99 | + if (\array_key_exists($alias, $bindings)){ |
|
| 100 | 100 | $binding = $bindings[$alias]; |
| 101 | - if ($followAlias && $binding::class === Alias::class) { |
|
| 102 | - if ($binding->alias === $alias) { |
|
| 101 | + if ($followAlias && $binding::class === Alias::class){ |
|
| 102 | + if ($binding->alias === $alias){ |
|
| 103 | 103 | break; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | return $binding->getReturnClass(); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if (\array_key_exists($alias, $injectors)) { |
|
| 117 | + if (\array_key_exists($alias, $injectors)){ |
|
| 118 | 118 | $injector = $injectors[$alias]; |
| 119 | 119 | $binding = $bindings[$alias] ?? null; |
| 120 | 120 | return $alias; |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // Go to parent scope |
| 124 | 124 | $parent = $actor->scope->getParentActor(); |
| 125 | - if ($parent === null) { |
|
| 125 | + if ($parent === null){ |
|
| 126 | 126 | break; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | $actor = $parent; |
| 130 | - } while (true); |
|
| 130 | + }while (true); |
|
| 131 | 131 | |
| 132 | 132 | return \class_exists($alias) ? $alias : null; |
| 133 | 133 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | public function resolveBinding( |
| 136 | 136 | object $binding, |
| 137 | 137 | string $alias, |
| 138 | - \Stringable|string|null $context, |
|
| 138 | + \Stringable | string | null $context, |
|
| 139 | 139 | array $arguments, |
| 140 | 140 | Tracer $tracer, |
| 141 | 141 | ): mixed { |
@@ -192,18 +192,18 @@ discard block |
||
| 192 | 192 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer) |
| 193 | 193 | { |
| 194 | 194 | $context = $ctx->context; |
| 195 | - try { |
|
| 195 | + try{ |
|
| 196 | 196 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 197 | - } catch (\ReflectionException $e) { |
|
| 197 | + }catch (\ReflectionException $e){ |
|
| 198 | 198 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $injector = $binding->injector; |
| 202 | 202 | |
| 203 | - try { |
|
| 203 | + try{ |
|
| 204 | 204 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 205 | 205 | |
| 206 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 206 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 207 | 207 | throw new InjectionException( |
| 208 | 208 | \sprintf( |
| 209 | 209 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | static $cache = []; |
| 218 | 218 | $extended = $cache[$injectorInstance::class] ??= ( |
| 219 | 219 | static fn(\ReflectionType $type): bool => |
| 220 | - $type::class === \ReflectionUnionType::class || (string) $type === 'mixed' |
|
| 220 | + $type::class === \ReflectionUnionType::class || (string)$type === 'mixed' |
|
| 221 | 221 | )( |
| 222 | 222 | ($refMethod = new \ReflectionMethod($injectorInstance, 'createInjection')) |
| 223 | 223 | ->getParameters()[1]->getType() |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | $instance = $injectorInstance->createInjection($reflection, match (true) { |
| 228 | 228 | $asIs => $context, |
| 229 | 229 | $context instanceof \ReflectionParameter => $context->getName(), |
| 230 | - default => (string) $context, |
|
| 230 | + default => (string)$context, |
|
| 231 | 231 | }); |
| 232 | 232 | |
| 233 | - if (!$reflection->isInstance($instance)) { |
|
| 233 | + if (!$reflection->isInstance($instance)){ |
|
| 234 | 234 | throw new InjectionException( |
| 235 | 235 | \sprintf( |
| 236 | 236 | "Invalid injection response for '%s'.", |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $instance; |
| 243 | - } catch (TracedContainerException $e) { |
|
| 243 | + }catch (TracedContainerException $e){ |
|
| 244 | 244 | throw isset($injectorInstance) ? $e : $e::extendTracedException(\sprintf( |
| 245 | 245 | 'Can\'t resolve `%s`.', |
| 246 | 246 | $tracer->getRootAlias(), |
| 247 | 247 | ), $tracer->getTraces(), $e); |
| 248 | - } finally { |
|
| 248 | + }finally{ |
|
| 249 | 249 | $this->state->bindings[$ctx->class] ??= $binding; |
| 250 | 250 | } |
| 251 | 251 | } |
@@ -253,22 +253,22 @@ discard block |
||
| 253 | 253 | private function resolveAlias( |
| 254 | 254 | Config\Alias $binding, |
| 255 | 255 | string $alias, |
| 256 | - \Stringable|string|null $context, |
|
| 256 | + \Stringable | string | null $context, |
|
| 257 | 257 | array $arguments, |
| 258 | 258 | Tracer $tracer, |
| 259 | 259 | ): mixed { |
| 260 | - if ($binding->alias === $alias) { |
|
| 260 | + if ($binding->alias === $alias){ |
|
| 261 | 261 | $instance = $this->autowire( |
| 262 | 262 | new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []), |
| 263 | 263 | $arguments, |
| 264 | 264 | $this, |
| 265 | 265 | $tracer, |
| 266 | 266 | ); |
| 267 | - } else { |
|
| 268 | - try { |
|
| 267 | + }else{ |
|
| 268 | + try{ |
|
| 269 | 269 | //Binding is pointing to something else |
| 270 | 270 | $instance = $this->factory->make($binding->alias, $arguments, $context); |
| 271 | - } catch (TracedContainerException $e) { |
|
| 271 | + }catch (TracedContainerException $e){ |
|
| 272 | 272 | throw $e::extendTracedException( |
| 273 | 273 | $alias === $tracer->getRootAlias() |
| 274 | 274 | ? "Can't resolve `{$alias}`." |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | return $instance; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
|
| 288 | + private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable | string | null $context): mixed |
|
| 289 | 289 | { |
| 290 | - if ($context instanceof RetryContext) { |
|
| 290 | + if ($context instanceof RetryContext){ |
|
| 291 | 291 | return $binding->fallbackFactory === null |
| 292 | 292 | ? throw new RecursiveProxyException( |
| 293 | 293 | $alias, |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | |
| 299 | 299 | $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy()); |
| 300 | 300 | |
| 301 | - if ($binding->singleton) { |
|
| 301 | + if ($binding->singleton){ |
|
| 302 | 302 | $this->state->singletons[$alias] = $result; |
| 303 | 303 | } |
| 304 | 304 | |
@@ -308,11 +308,11 @@ discard block |
||
| 308 | 308 | private function resolveShared( |
| 309 | 309 | Config\Shared $binding, |
| 310 | 310 | string $alias, |
| 311 | - \Stringable|string|null $context, |
|
| 311 | + \Stringable | string | null $context, |
|
| 312 | 312 | array $arguments, |
| 313 | 313 | Tracer $tracer, |
| 314 | 314 | ): object { |
| 315 | - if ($arguments !== []) { |
|
| 315 | + if ($arguments !== []){ |
|
| 316 | 316 | // Avoid singleton cache |
| 317 | 317 | return $this->createInstance( |
| 318 | 318 | new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false), |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | ); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - if ($binding->singleton) { |
|
| 325 | + if ($binding->singleton){ |
|
| 326 | 326 | $this->state->singletons[$alias] = $binding->value; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -332,16 +332,16 @@ discard block |
||
| 332 | 332 | private function resolveAutowire( |
| 333 | 333 | Config\Autowire $binding, |
| 334 | 334 | string $alias, |
| 335 | - \Stringable|string|null $context, |
|
| 335 | + \Stringable | string | null $context, |
|
| 336 | 336 | array $arguments, |
| 337 | 337 | Tracer $tracer, |
| 338 | 338 | ): mixed { |
| 339 | 339 | $target = $binding->autowire->alias; |
| 340 | 340 | $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 341 | 341 | |
| 342 | - if ($alias === $target) { |
|
| 342 | + if ($alias === $target){ |
|
| 343 | 343 | $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer); |
| 344 | - } else { |
|
| 344 | + }else{ |
|
| 345 | 345 | $instance = $binding->autowire->resolve($this->factory, $arguments); |
| 346 | 346 | $this->validateConstraint($instance, $ctx); |
| 347 | 347 | } |
@@ -350,24 +350,24 @@ discard block |
||
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | private function resolveFactory( |
| 353 | - Config\Factory|Config\DeferredFactory $binding, |
|
| 353 | + Config\Factory | Config\DeferredFactory $binding, |
|
| 354 | 354 | string $alias, |
| 355 | - \Stringable|string|null $context, |
|
| 355 | + \Stringable | string | null $context, |
|
| 356 | 356 | array $arguments, |
| 357 | 357 | Tracer $tracer, |
| 358 | 358 | ): mixed { |
| 359 | 359 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null); |
| 360 | - try { |
|
| 360 | + try{ |
|
| 361 | 361 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 362 | 362 | ? ($binding->factory)() |
| 363 | 363 | : $this->invoker->invoke($binding->factory, $arguments); |
| 364 | - } catch (NotCallableException $e) { |
|
| 364 | + }catch (NotCallableException $e){ |
|
| 365 | 365 | throw TracedContainerException::createWithTrace( |
| 366 | 366 | \sprintf('Invalid callable binding for `%s`.', $ctx->alias), |
| 367 | 367 | $tracer->getTraces(), |
| 368 | 368 | $e, |
| 369 | 369 | ); |
| 370 | - } catch (TracedContainerException $e) { |
|
| 370 | + }catch (TracedContainerException $e){ |
|
| 371 | 371 | throw $e::extendTracedException( |
| 372 | 372 | \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()), |
| 373 | 373 | $tracer->getTraces(), |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | ); |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if (\is_object($instance)) { |
|
| 378 | + if (\is_object($instance)){ |
|
| 379 | 379 | $this->validateConstraint($instance, $ctx); |
| 380 | 380 | return $this->registerInstance($ctx, $instance); |
| 381 | 381 | } |
@@ -386,14 +386,14 @@ discard block |
||
| 386 | 386 | private function resolveWeakReference( |
| 387 | 387 | Config\WeakReference $binding, |
| 388 | 388 | string $alias, |
| 389 | - \Stringable|string|null $context, |
|
| 389 | + \Stringable | string | null $context, |
|
| 390 | 390 | array $arguments, |
| 391 | 391 | Tracer $tracer, |
| 392 | 392 | ): ?object { |
| 393 | 393 | $avoidCache = $arguments !== []; |
| 394 | 394 | |
| 395 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 396 | - try { |
|
| 395 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 396 | + try{ |
|
| 397 | 397 | $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
| 398 | 398 | |
| 399 | 399 | $object = $this->createInstance( |
@@ -402,17 +402,17 @@ discard block |
||
| 402 | 402 | $this, |
| 403 | 403 | $tracer, |
| 404 | 404 | ); |
| 405 | - if ($avoidCache) { |
|
| 405 | + if ($avoidCache){ |
|
| 406 | 406 | return $object; |
| 407 | 407 | } |
| 408 | 408 | $binding->reference = \WeakReference::create($object); |
| 409 | - } catch (\Throwable) { |
|
| 409 | + }catch (\Throwable){ |
|
| 410 | 410 | throw ContainerException::createWithTrace(\sprintf( |
| 411 | 411 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
| 412 | 412 | $tracer->getRootAlias(), |
| 413 | 413 | $alias, |
| 414 | 414 | ), $tracer->getTraces()); |
| 415 | - } finally { |
|
| 415 | + }finally{ |
|
| 416 | 416 | $tracer->pop(); |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -428,13 +428,13 @@ discard block |
||
| 428 | 428 | object $instance, |
| 429 | 429 | Ctx $ctx, |
| 430 | 430 | ): void { |
| 431 | - if ($this->options->checkScope) { |
|
| 431 | + if ($this->options->checkScope){ |
|
| 432 | 432 | // Check scope name |
| 433 | 433 | $ctx->reflection ??= new \ReflectionClass($instance); |
| 434 | 434 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 435 | - if ($scopeName !== null) { |
|
| 435 | + if ($scopeName !== null){ |
|
| 436 | 436 | $scope = $this->scope; |
| 437 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 437 | + while ($scope->getScopeName() !== $scopeName){ |
|
| 438 | 438 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 439 | 439 | } |
| 440 | 440 | } |
@@ -461,26 +461,26 @@ discard block |
||
| 461 | 461 | Tracer $tracer, |
| 462 | 462 | ): object { |
| 463 | 463 | $class = $ctx->class; |
| 464 | - try { |
|
| 464 | + try{ |
|
| 465 | 465 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 466 | - } catch (\ReflectionException $e) { |
|
| 466 | + }catch (\ReflectionException $e){ |
|
| 467 | 467 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | // Check Scope attribute |
| 471 | 471 | $actor = $fallbackActor ?? $this; |
| 472 | - if ($this->options->checkScope) { # todo |
|
| 472 | + if ($this->options->checkScope){ # todo |
|
| 473 | 473 | $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null); |
| 474 | - if ($ar !== null) { |
|
| 474 | + if ($ar !== null){ |
|
| 475 | 475 | /** @var Attribute\Scope $attr */ |
| 476 | 476 | $attr = $ar->newInstance(); |
| 477 | 477 | $scope = $this->scope; |
| 478 | 478 | $actor = $this; |
| 479 | 479 | // Go through all parent scopes |
| 480 | 480 | $needed = $actor; |
| 481 | - while ($attr->name !== $scope->getScopeName()) { |
|
| 481 | + while ($attr->name !== $scope->getScopeName()){ |
|
| 482 | 482 | $needed = $scope->getParentActor(); |
| 483 | - if ($needed === null) { |
|
| 483 | + if ($needed === null){ |
|
| 484 | 484 | throw new BadScopeException($attr->name, $class); |
| 485 | 485 | } |
| 486 | 486 | |
@@ -493,11 +493,11 @@ discard block |
||
| 493 | 493 | } # todo |
| 494 | 494 | |
| 495 | 495 | // We have to construct class using external injector when we know the exact context |
| 496 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 496 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
| 497 | 497 | return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer); |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - if (!$reflection->isInstantiable()) { |
|
| 500 | + if (!$reflection->isInstantiable()){ |
|
| 501 | 501 | $itIs = match (true) { |
| 502 | 502 | $reflection->isEnum() => 'Enum', |
| 503 | 503 | $reflection->isAbstract() => 'Abstract class', |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | $constructor = $reflection->getConstructor(); |
| 513 | 513 | |
| 514 | - if ($constructor !== null) { |
|
| 515 | - try { |
|
| 514 | + if ($constructor !== null){ |
|
| 515 | + try{ |
|
| 516 | 516 | $newScope = $this !== $actor; |
| 517 | 517 | $debug = [ |
| 518 | 518 | 'action' => 'resolve arguments', |
@@ -526,39 +526,39 @@ discard block |
||
| 526 | 526 | $tracer->push($newScope, ...$debug); |
| 527 | 527 | $tracer->push(true); |
| 528 | 528 | $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments); |
| 529 | - } catch (ValidationException $e) { |
|
| 529 | + }catch (ValidationException $e){ |
|
| 530 | 530 | throw TracedContainerException::createWithTrace(\sprintf( |
| 531 | 531 | 'Can\'t resolve `%s`. %s', |
| 532 | 532 | $tracer->getRootAlias(), |
| 533 | 533 | $e->getMessage(), |
| 534 | 534 | ), $tracer->getTraces()); |
| 535 | - } catch (TracedContainerException $e) { |
|
| 535 | + }catch (TracedContainerException $e){ |
|
| 536 | 536 | throw $e::extendTracedException(\sprintf( |
| 537 | 537 | 'Can\'t resolve `%s`.', |
| 538 | 538 | $tracer->getRootAlias(), |
| 539 | 539 | ), $tracer->getTraces(), $e); |
| 540 | - } finally { |
|
| 540 | + }finally{ |
|
| 541 | 541 | $tracer->pop($newScope); |
| 542 | 542 | $tracer->pop(false); |
| 543 | 543 | } |
| 544 | - try { |
|
| 544 | + try{ |
|
| 545 | 545 | // Using constructor with resolved arguments |
| 546 | 546 | $tracer->push(false, call: "$class::__construct", arguments: $args); |
| 547 | 547 | $tracer->push(true); |
| 548 | 548 | $instance = new $class(...$args); |
| 549 | - } catch (\TypeError $e) { |
|
| 549 | + }catch (\TypeError $e){ |
|
| 550 | 550 | throw new WrongTypeException($constructor, $e); |
| 551 | - } catch (TracedContainerException $e) { |
|
| 551 | + }catch (TracedContainerException $e){ |
|
| 552 | 552 | throw $e::extendTracedException(\sprintf( |
| 553 | 553 | 'Can\'t resolve `%s`: failed constructing `%s`.', |
| 554 | 554 | $tracer->getRootAlias(), |
| 555 | 555 | $class, |
| 556 | 556 | ), $tracer->getTraces(), $e); |
| 557 | - } finally { |
|
| 557 | + }finally{ |
|
| 558 | 558 | $tracer->pop(true); |
| 559 | 559 | $tracer->pop(false); |
| 560 | 560 | } |
| 561 | - } else { |
|
| 561 | + }else{ |
|
| 562 | 562 | // No constructor specified |
| 563 | 563 | $instance = $reflection->newInstance(); |
| 564 | 564 | } |
@@ -590,12 +590,12 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | private function isSingleton(Ctx $ctx): bool |
| 592 | 592 | { |
| 593 | - if (is_bool($ctx->singleton)) { |
|
| 593 | + if (is_bool($ctx->singleton)){ |
|
| 594 | 594 | return $ctx->singleton; |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 598 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 598 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 599 | 599 | return true; |
| 600 | 600 | } |
| 601 | 601 | |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | * @var Attribute\Finalize|null $attribute |
| 610 | 610 | */ |
| 611 | 611 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 612 | - if ($attribute === null) { |
|
| 612 | + if ($attribute === null){ |
|
| 613 | 613 | return null; |
| 614 | 614 | } |
| 615 | 615 | |
@@ -623,10 +623,10 @@ discard block |
||
| 623 | 623 | { |
| 624 | 624 | $scope = $this->scope; |
| 625 | 625 | |
| 626 | - while ($scope !== null) { |
|
| 627 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 628 | - if ($instance instanceof $class) { |
|
| 629 | - foreach ($inflectors as $inflector) { |
|
| 626 | + while ($scope !== null){ |
|
| 627 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 628 | + if ($instance instanceof $class){ |
|
| 629 | + foreach ($inflectors as $inflector){ |
|
| 630 | 630 | $instance = $inflector->getParametersCount() > 1 |
| 631 | 631 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 632 | 632 | : ($inflector->inflector)($instance); |
@@ -642,9 +642,9 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 644 | 644 | { |
| 645 | - try { |
|
| 645 | + try{ |
|
| 646 | 646 | $this->resolver->validateArguments($reflection, $arguments); |
| 647 | - } catch (\Throwable) { |
|
| 647 | + }catch (\Throwable){ |
|
| 648 | 648 | return false; |
| 649 | 649 | } |
| 650 | 650 | |
@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | public function push(bool $nextLevel, mixed ...$details): void |
| 35 | 35 | { |
| 36 | 36 | $trace = $details === [] ? null : new Trace($details); |
| 37 | - if ($nextLevel || $this->traces === []) { |
|
| 37 | + if ($nextLevel || $this->traces === []){ |
|
| 38 | 38 | $this->traces[] = $trace === null ? [] : [$trace]; |
| 39 | - } elseif ($trace !== null) { |
|
| 39 | + } elseif ($trace !== null){ |
|
| 40 | 40 | $this->traces[\array_key_last($this->traces)][] = $trace; |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function pop(bool $previousLevel = false): void |
| 45 | 45 | { |
| 46 | - if ($this->traces === []) { |
|
| 46 | + if ($this->traces === []){ |
|
| 47 | 47 | return; |
| 48 | 48 | } |
| 49 | - if ($previousLevel) { |
|
| 49 | + if ($previousLevel){ |
|
| 50 | 50 | \array_pop($this->traces); |
| 51 | 51 | return; |
| 52 | 52 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | public function __toString(): string |
| 64 | 64 | { |
| 65 | - return $this->traces === [] ? '' : "Resolving trace:\n" . self::renderTraceList($this->traces); |
|
| 65 | + return $this->traces === [] ? '' : "Resolving trace:\n".self::renderTraceList($this->traces); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $result = []; |
| 74 | 74 | $i = 0; |
| 75 | - foreach ($blocks as $block) { |
|
| 75 | + foreach ($blocks as $block){ |
|
| 76 | 76 | \array_push($result, ...self::blockToStringList($block, $i++)); |
| 77 | 77 | } |
| 78 | 78 | return \implode("\n", $result); |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | // Separator |
| 93 | 93 | $s = "\n"; |
| 94 | 94 | $nexPrefix = "$s$padding "; |
| 95 | - foreach ($items as $item) { |
|
| 96 | - $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string) $item); |
|
| 95 | + foreach ($items as $item){ |
|
| 96 | + $result[] = $firstPrefix.\str_replace($s, $nexPrefix, (string)$item); |
|
| 97 | 97 | } |
| 98 | 98 | return $result; |
| 99 | 99 | } |