@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
| 54 | 54 | |
| 55 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
| 55 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy){ |
|
| 56 | 56 | $proxy->bar(name: 'foo'); // Possible to run |
| 57 | 57 | }); |
| 58 | 58 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $proxy = $$var; |
| 93 | 93 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
| 94 | 94 | self::assertSame( |
| 95 | - ['foo' => 'foo','zap' => 'bar', 'gas' => 69], |
|
| 95 | + ['foo' => 'foo', 'zap' => 'bar', 'gas' => 69], |
|
| 96 | 96 | $proxy->extraVariadic(foo: 'foo', zap: 'bar', gas: 69), |
| 97 | 97 | ); |
| 98 | 98 | }); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
| 178 | 178 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
| 179 | 179 | |
| 180 | - $mock = $root->invoke(static fn(#[Proxy] MockInterface|EmptyInterface $mock) => $mock); |
|
| 180 | + $mock = $root->invoke(static fn(#[Proxy] MockInterface | EmptyInterface $mock) => $mock); |
|
| 181 | 181 | |
| 182 | 182 | self::assertInstanceOf(MockInterfaceImpl::class, $mock); |
| 183 | 183 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | { |
| 231 | 231 | \set_error_handler(static function (int $errno, string $error) use ($interface): void { |
| 232 | 232 | self::assertSame( |
| 233 | - \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be ' . |
|
| 233 | + \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be '. |
|
| 234 | 234 | 'impossible in version 4.0.', $interface), |
| 235 | 235 | $error |
| 236 | 236 | ); |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | public function testDeprecationProxyConfigDontThrowIfNotConstructed(string $interface): void |
| 287 | 287 | { |
| 288 | 288 | \set_error_handler(static function (int $errno, string $error) use ($interface): void { |
| 289 | - self::fail('Unexpected error: ' . $error); |
|
| 289 | + self::fail('Unexpected error: '.$error); |
|
| 290 | 290 | }); |
| 291 | 291 | |
| 292 | 292 | $root = new Container(); |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | #[DataProvider('invalidDeprecationProxyArgsDataProvider')] |
| 309 | - public function testDeprecationProxyConfigArgsRequiredException(string|null $scope, string|null $version): void |
|
| 309 | + public function testDeprecationProxyConfigArgsRequiredException(string | null $scope, string | null $version): void |
|
| 310 | 310 | { |
| 311 | 311 | self::expectException(\InvalidArgumentException::class); |
| 312 | 312 | self::expectExceptionMessage('Scope and version or custom message must be provided.'); |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | $root->invoke(static function ( |
| 36 | 36 | #[Proxy] MockInterface $mock, |
| 37 | 37 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
| 38 | - ) use ($var) { |
|
| 38 | + ) use ($var) |
|
| 39 | + { |
|
| 39 | 40 | /** @var MockInterfaceImpl $proxy */ |
| 40 | 41 | $proxy = $$var; |
| 41 | 42 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -52,7 +53,8 @@ discard block |
||
| 52 | 53 | |
| 53 | 54 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
| 54 | 55 | |
| 55 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
| 56 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy) |
|
| 57 | + { |
|
| 56 | 58 | $proxy->bar(name: 'foo'); // Possible to run |
| 57 | 59 | }); |
| 58 | 60 | } |
@@ -67,7 +69,8 @@ discard block |
||
| 67 | 69 | $root->invoke(static function ( |
| 68 | 70 | #[Proxy] MockInterface $mock, |
| 69 | 71 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
| 70 | - ) use ($var) { |
|
| 72 | + ) use ($var) |
|
| 73 | + { |
|
| 71 | 74 | /** @var MockInterfaceImpl $proxy */ |
| 72 | 75 | $proxy = $$var; |
| 73 | 76 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extra('foo', 'bar', 'baz', 69)); |
@@ -87,7 +90,8 @@ discard block |
||
| 87 | 90 | $root->invoke(static function ( |
| 88 | 91 | #[Proxy] MockInterface $mock, |
| 89 | 92 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
| 90 | - ) use ($var) { |
|
| 93 | + ) use ($var) |
|
| 94 | + { |
|
| 91 | 95 | /** @var MockInterfaceImpl $proxy */ |
| 92 | 96 | $proxy = $$var; |
| 93 | 97 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
@@ -109,7 +113,8 @@ discard block |
||
| 109 | 113 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
| 110 | 114 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
| 111 | 115 | |
| 112 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
| 116 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
| 117 | + { |
|
| 113 | 118 | /** @var MockInterfaceImpl $proxy */ |
| 114 | 119 | $proxy = $$var; |
| 115 | 120 | $str = 'bar'; |
@@ -129,7 +134,8 @@ discard block |
||
| 129 | 134 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
| 130 | 135 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
| 131 | 136 | |
| 132 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
| 137 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
| 138 | + { |
|
| 133 | 139 | /** @var MockInterfaceImpl $proxy */ |
| 134 | 140 | $proxy = $$var; |
| 135 | 141 | |
@@ -152,7 +158,8 @@ discard block |
||
| 152 | 158 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
| 153 | 159 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
| 154 | 160 | |
| 155 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
| 161 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
| 162 | + { |
|
| 156 | 163 | /** @var MockInterfaceImpl $proxy */ |
| 157 | 164 | $proxy = $$var; |
| 158 | 165 | $str1 = 'bar'; |
@@ -193,7 +200,8 @@ discard block |
||
| 193 | 200 | $this->assertInstanceOf($interface, $proxy); |
| 194 | 201 | $this->assertNotInstanceOf(MockInterfaceImpl::class, $proxy); |
| 195 | 202 | |
| 196 | - $root->runScope(new Scope('foo'), static function (Container $container) use ($interface, $proxy) { |
|
| 203 | + $root->runScope(new Scope('foo'), static function (Container $container) use ($interface, $proxy) |
|
| 204 | + { |
|
| 197 | 205 | $proxy->bar(name: 'foo'); // Possible to run |
| 198 | 206 | self::assertSame('foo', $proxy->baz('foo', 42)); |
| 199 | 207 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -243,7 +251,8 @@ discard block |
||
| 243 | 251 | $proxy = $root->get($interface); |
| 244 | 252 | $this->assertInstanceOf($interface, $proxy); |
| 245 | 253 | |
| 246 | - $root->runScope(new Scope('foo'), static function () use ($proxy) { |
|
| 254 | + $root->runScope(new Scope('foo'), static function () use ($proxy) |
|
| 255 | + { |
|
| 247 | 256 | $proxy->bar(name: 'foo'); // Possible to run |
| 248 | 257 | self::assertSame('foo', $proxy->baz('foo', 42)); |
| 249 | 258 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -271,7 +280,8 @@ discard block |
||
| 271 | 280 | $proxy = $root->get($interface); |
| 272 | 281 | $this->assertInstanceOf($interface, $proxy); |
| 273 | 282 | |
| 274 | - $root->runScope(new Scope('foo'), static function () use ($proxy) { |
|
| 283 | + $root->runScope(new Scope('foo'), static function () use ($proxy) |
|
| 284 | + { |
|
| 275 | 285 | $proxy->bar(name: 'foo'); // Possible to run |
| 276 | 286 | self::assertSame('foo', $proxy->baz('foo', 42)); |
| 277 | 287 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -293,7 +303,8 @@ discard block |
||
| 293 | 303 | $root->getBinder('foo')->bindSingleton($interface, Stub\MockInterfaceImpl::class); |
| 294 | 304 | $root->bindSingleton($interface, new Config\DeprecationProxy($interface, true, 'foo', '4.0')); |
| 295 | 305 | |
| 296 | - $root->runScope(new Scope('foo'), static function (Container $container) use ($interface) { |
|
| 306 | + $root->runScope(new Scope('foo'), static function (Container $container) use ($interface) |
|
| 307 | + { |
|
| 297 | 308 | $proxy = $container->get($interface); |
| 298 | 309 | |
| 299 | 310 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @throws \Throwable |
| 65 | 65 | */ |
| 66 | - public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
|
| 66 | + public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed |
|
| 67 | 67 | { |
| 68 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 68 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
| 69 | 69 | return $this->state->singletons[$alias]; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $binding = $this->state->bindings[$alias] ?? null; |
| 73 | 73 | |
| 74 | - if ($binding === null) { |
|
| 74 | + if ($binding === null){ |
|
| 75 | 75 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - try { |
|
| 78 | + try{ |
|
| 79 | 79 | $this->tracer->push( |
| 80 | 80 | false, |
| 81 | 81 | action: 'resolve from binding', |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 106 | 106 | default => $binding, |
| 107 | 107 | }; |
| 108 | - } finally { |
|
| 108 | + }finally{ |
|
| 109 | 109 | $this->state->bindings[$alias] ??= $binding; |
| 110 | 110 | $this->tracer->pop(true); |
| 111 | 111 | $this->tracer->pop(false); |
@@ -119,18 +119,18 @@ discard block |
||
| 119 | 119 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
| 120 | 120 | { |
| 121 | 121 | $context = $ctx->context; |
| 122 | - try { |
|
| 122 | + try{ |
|
| 123 | 123 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 124 | - } catch (\ReflectionException $e) { |
|
| 124 | + }catch (\ReflectionException $e){ |
|
| 125 | 125 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $injector = $binding->injector; |
| 129 | 129 | |
| 130 | - try { |
|
| 130 | + try{ |
|
| 131 | 131 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 132 | 132 | |
| 133 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 133 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 134 | 134 | throw new InjectionException( |
| 135 | 135 | \sprintf( |
| 136 | 136 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | default => (string)$context, |
| 158 | 158 | }); |
| 159 | 159 | |
| 160 | - if (!$reflection->isInstance($instance)) { |
|
| 160 | + if (!$reflection->isInstance($instance)){ |
|
| 161 | 161 | throw new InjectionException( |
| 162 | 162 | \sprintf( |
| 163 | 163 | "Invalid injection response for '%s'.", |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | return $instance; |
| 170 | - } finally { |
|
| 170 | + }finally{ |
|
| 171 | 171 | $this->state->bindings[$ctx->class] ??= $binding; |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | private function resolveAlias( |
| 176 | 176 | Config\Alias $binding, |
| 177 | 177 | string $alias, |
| 178 | - Stringable|string|null $context, |
|
| 178 | + Stringable | string | null $context, |
|
| 179 | 179 | array $arguments, |
| 180 | 180 | ): mixed { |
| 181 | 181 | $result = $binding->alias === $alias |
| 182 | 182 | ? $this->autowire( |
| 183 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
| 183 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
| 184 | 184 | $arguments, |
| 185 | 185 | ) |
| 186 | 186 | //Binding is pointing to something else |
| 187 | 187 | : $this->make($binding->alias, $arguments, $context); |
| 188 | 188 | |
| 189 | - if ($binding->singleton && $arguments === []) { |
|
| 189 | + if ($binding->singleton && $arguments === []){ |
|
| 190 | 190 | $this->state->singletons[$alias] = $result; |
| 191 | 191 | } |
| 192 | 192 | |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | private function resolveProxy( |
| 197 | 197 | Config\Proxy $binding, |
| 198 | 198 | string $alias, |
| 199 | - Stringable|string|null $context, |
|
| 199 | + Stringable | string | null $context, |
|
| 200 | 200 | array $arguments, |
| 201 | 201 | ): mixed { |
| 202 | 202 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 203 | 203 | |
| 204 | - if ($binding->singleton && $arguments === []) { |
|
| 204 | + if ($binding->singleton && $arguments === []){ |
|
| 205 | 205 | $this->state->singletons[$alias] = $result; |
| 206 | 206 | } |
| 207 | 207 | |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | private function resolveShared( |
| 212 | 212 | Config\Shared $binding, |
| 213 | 213 | string $alias, |
| 214 | - Stringable|string|null $context, |
|
| 214 | + Stringable | string | null $context, |
|
| 215 | 215 | array $arguments, |
| 216 | 216 | ): object { |
| 217 | 217 | $avoidCache = $arguments !== []; |
| 218 | 218 | return $avoidCache |
| 219 | 219 | ? $this->createInstance( |
| 220 | - new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
|
| 220 | + new Ctx(alias : $alias, class : $binding->value::class, context : $context), |
|
| 221 | 221 | $arguments, |
| 222 | 222 | ) |
| 223 | 223 | : $binding->value; |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | private function resolveAutowire( |
| 227 | 227 | Config\Autowire $binding, |
| 228 | 228 | string $alias, |
| 229 | - Stringable|string|null $context, |
|
| 229 | + Stringable | string | null $context, |
|
| 230 | 230 | array $arguments, |
| 231 | 231 | ): mixed { |
| 232 | 232 | $instance = $binding->autowire->resolve($this, $arguments); |
@@ -236,17 +236,17 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | private function resolveFactory( |
| 239 | - Config\Factory|Config\DeferredFactory $binding, |
|
| 239 | + Config\Factory | Config\DeferredFactory $binding, |
|
| 240 | 240 | string $alias, |
| 241 | - Stringable|string|null $context, |
|
| 241 | + Stringable | string | null $context, |
|
| 242 | 242 | array $arguments, |
| 243 | 243 | ): mixed { |
| 244 | 244 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 245 | - try { |
|
| 245 | + try{ |
|
| 246 | 246 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 247 | 247 | ? ($binding->factory)() |
| 248 | 248 | : $this->invoker->invoke($binding->factory, $arguments); |
| 249 | - } catch (NotCallableException $e) { |
|
| 249 | + }catch (NotCallableException $e){ |
|
| 250 | 250 | throw new ContainerException( |
| 251 | 251 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 252 | 252 | $e->getCode(), |
@@ -260,24 +260,24 @@ discard block |
||
| 260 | 260 | private function resolveWeakReference( |
| 261 | 261 | Config\WeakReference $binding, |
| 262 | 262 | string $alias, |
| 263 | - Stringable|string|null $context, |
|
| 263 | + Stringable | string | null $context, |
|
| 264 | 264 | array $arguments, |
| 265 | 265 | ): ?object { |
| 266 | 266 | $avoidCache = $arguments !== []; |
| 267 | 267 | |
| 268 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 269 | - try { |
|
| 268 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 269 | + try{ |
|
| 270 | 270 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 271 | 271 | |
| 272 | 272 | $object = $this->createInstance( |
| 273 | 273 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 274 | 274 | $arguments, |
| 275 | 275 | ); |
| 276 | - if ($avoidCache) { |
|
| 276 | + if ($avoidCache){ |
|
| 277 | 277 | return $object; |
| 278 | 278 | } |
| 279 | 279 | $binding->reference = WeakReference::create($object); |
| 280 | - } catch (\Throwable) { |
|
| 280 | + }catch (\Throwable){ |
|
| 281 | 281 | throw new ContainerException( |
| 282 | 282 | $this->tracer->combineTraceMessage( |
| 283 | 283 | \sprintf( |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | ) |
| 288 | 288 | ) |
| 289 | 289 | ); |
| 290 | - } finally { |
|
| 290 | + }finally{ |
|
| 291 | 291 | $this->tracer->pop(); |
| 292 | 292 | } |
| 293 | 293 | } |
@@ -298,23 +298,23 @@ discard block |
||
| 298 | 298 | private function resolveWithoutBinding( |
| 299 | 299 | string $alias, |
| 300 | 300 | array $parameters = [], |
| 301 | - Stringable|string|null $context = null |
|
| 301 | + Stringable | string | null $context = null |
|
| 302 | 302 | ): mixed { |
| 303 | 303 | $parent = $this->scope->getParentFactory(); |
| 304 | 304 | |
| 305 | - if ($parent !== null) { |
|
| 306 | - try { |
|
| 305 | + if ($parent !== null){ |
|
| 306 | + try{ |
|
| 307 | 307 | $this->tracer->push(false, ...[ |
| 308 | 308 | 'current scope' => $this->scope->getScopeName(), |
| 309 | 309 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 310 | 310 | ]); |
| 311 | 311 | /** @psalm-suppress TooManyArguments */ |
| 312 | 312 | return $parent->make($alias, $parameters, $context); |
| 313 | - } catch (BadScopeException $e) { |
|
| 314 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 313 | + }catch (BadScopeException $e){ |
|
| 314 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
| 315 | 315 | throw $e; |
| 316 | 316 | } |
| 317 | - } catch (ContainerExceptionInterface $e) { |
|
| 317 | + }catch (ContainerExceptionInterface $e){ |
|
| 318 | 318 | $className = match (true) { |
| 319 | 319 | $e instanceof NotFoundException => NotFoundException::class, |
| 320 | 320 | default => ContainerException::class, |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | 'Can\'t resolve `%s`.', |
| 324 | 324 | $alias, |
| 325 | 325 | )), previous: $e); |
| 326 | - } finally { |
|
| 326 | + }finally{ |
|
| 327 | 327 | $this->tracer->pop(false); |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 332 | - try { |
|
| 332 | + try{ |
|
| 333 | 333 | //No direct instructions how to construct class, make is automatically |
| 334 | 334 | return $this->autowire( |
| 335 | 335 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 336 | 336 | $parameters, |
| 337 | 337 | ); |
| 338 | - } finally { |
|
| 338 | + }finally{ |
|
| 339 | 339 | $this->tracer->pop(false); |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | && |
| 357 | 357 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
| 358 | 358 | )) |
| 359 | - ) { |
|
| 359 | + ){ |
|
| 360 | 360 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
| 361 | 361 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 362 | 362 | $this->tracer->getRootAlias(), |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | // Check scope name |
| 386 | 386 | $ctx->reflection = new \ReflectionClass($instance); |
| 387 | 387 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 388 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
| 388 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
| 389 | 389 | throw new BadScopeException($scopeName, $instance::class); |
| 390 | 390 | } |
| 391 | 391 | |
@@ -412,24 +412,24 @@ discard block |
||
| 412 | 412 | array $arguments, |
| 413 | 413 | ): object { |
| 414 | 414 | $class = $ctx->class; |
| 415 | - try { |
|
| 415 | + try{ |
|
| 416 | 416 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 417 | - } catch (\ReflectionException $e) { |
|
| 417 | + }catch (\ReflectionException $e){ |
|
| 418 | 418 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | // Check scope name |
| 422 | 422 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 423 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 423 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
| 424 | 424 | throw new BadScopeException($scope, $class); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // We have to construct class using external injector when we know the exact context |
| 428 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 428 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
| 429 | 429 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - if (!$reflection->isInstantiable()) { |
|
| 432 | + if (!$reflection->isInstantiable()){ |
|
| 433 | 433 | $itIs = match (true) { |
| 434 | 434 | $reflection->isEnum() => 'Enum', |
| 435 | 435 | $reflection->isAbstract() => 'Abstract class', |
@@ -442,12 +442,12 @@ discard block |
||
| 442 | 442 | |
| 443 | 443 | $constructor = $reflection->getConstructor(); |
| 444 | 444 | |
| 445 | - if ($constructor !== null) { |
|
| 446 | - try { |
|
| 445 | + if ($constructor !== null){ |
|
| 446 | + try{ |
|
| 447 | 447 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 448 | 448 | $this->tracer->push(true); |
| 449 | 449 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
| 450 | - } catch (ValidationException $e) { |
|
| 450 | + }catch (ValidationException $e){ |
|
| 451 | 451 | throw new ContainerException( |
| 452 | 452 | $this->tracer->combineTraceMessage( |
| 453 | 453 | \sprintf( |
@@ -457,22 +457,22 @@ discard block |
||
| 457 | 457 | ) |
| 458 | 458 | ), |
| 459 | 459 | ); |
| 460 | - } finally { |
|
| 460 | + }finally{ |
|
| 461 | 461 | $this->tracer->pop(true); |
| 462 | 462 | $this->tracer->pop(false); |
| 463 | 463 | } |
| 464 | - try { |
|
| 464 | + try{ |
|
| 465 | 465 | // Using constructor with resolved arguments |
| 466 | 466 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 467 | 467 | $this->tracer->push(true); |
| 468 | 468 | $instance = new $class(...$args); |
| 469 | - } catch (\TypeError $e) { |
|
| 469 | + }catch (\TypeError $e){ |
|
| 470 | 470 | throw new WrongTypeException($constructor, $e); |
| 471 | - } finally { |
|
| 471 | + }finally{ |
|
| 472 | 472 | $this->tracer->pop(true); |
| 473 | 473 | $this->tracer->pop(false); |
| 474 | 474 | } |
| 475 | - } else { |
|
| 475 | + }else{ |
|
| 476 | 476 | // No constructor specified |
| 477 | 477 | $instance = $reflection->newInstance(); |
| 478 | 478 | } |
@@ -490,13 +490,13 @@ discard block |
||
| 490 | 490 | $instance = $this->runInflector($instance); |
| 491 | 491 | |
| 492 | 492 | //Declarative singletons |
| 493 | - if ($this->isSingleton($ctx)) { |
|
| 493 | + if ($this->isSingleton($ctx)){ |
|
| 494 | 494 | $this->state->singletons[$ctx->alias] = $instance; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // Register finalizer |
| 498 | 498 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 499 | - if ($finalizer !== null) { |
|
| 499 | + if ($finalizer !== null){ |
|
| 500 | 500 | $this->state->finalizers[] = $finalizer; |
| 501 | 501 | } |
| 502 | 502 | |
@@ -508,12 +508,12 @@ discard block |
||
| 508 | 508 | */ |
| 509 | 509 | private function isSingleton(Ctx $ctx): bool |
| 510 | 510 | { |
| 511 | - if ($ctx->singleton === true) { |
|
| 511 | + if ($ctx->singleton === true){ |
|
| 512 | 512 | return true; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 516 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 516 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 517 | 517 | return true; |
| 518 | 518 | } |
| 519 | 519 | |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | * @var Attribute\Finalize|null $attribute |
| 528 | 528 | */ |
| 529 | 529 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 530 | - if ($attribute === null) { |
|
| 530 | + if ($attribute === null){ |
|
| 531 | 531 | return null; |
| 532 | 532 | } |
| 533 | 533 | |
@@ -541,10 +541,10 @@ discard block |
||
| 541 | 541 | { |
| 542 | 542 | $scope = $this->scope; |
| 543 | 543 | |
| 544 | - while ($scope !== null) { |
|
| 545 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 546 | - if ($instance instanceof $class) { |
|
| 547 | - foreach ($inflectors as $inflector) { |
|
| 544 | + while ($scope !== null){ |
|
| 545 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 546 | + if ($instance instanceof $class){ |
|
| 547 | + foreach ($inflectors as $inflector){ |
|
| 548 | 548 | $instance = $inflector->getParametersCount() > 1 |
| 549 | 549 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 550 | 550 | : ($inflector->inflector)($instance); |
@@ -560,9 +560,9 @@ discard block |
||
| 560 | 560 | |
| 561 | 561 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 562 | 562 | { |
| 563 | - try { |
|
| 563 | + try{ |
|
| 564 | 564 | $this->resolver->validateArguments($reflection, $arguments); |
| 565 | - } catch (\Throwable) { |
|
| 565 | + }catch (\Throwable){ |
|
| 566 | 566 | return false; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -65,17 +65,20 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
| 67 | 67 | { |
| 68 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 68 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
| 69 | + { |
|
| 69 | 70 | return $this->state->singletons[$alias]; |
| 70 | 71 | } |
| 71 | 72 | |
| 72 | 73 | $binding = $this->state->bindings[$alias] ?? null; |
| 73 | 74 | |
| 74 | - if ($binding === null) { |
|
| 75 | + if ($binding === null) |
|
| 76 | + { |
|
| 75 | 77 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | - try { |
|
| 80 | + try |
|
| 81 | + { |
|
| 79 | 82 | $this->tracer->push( |
| 80 | 83 | false, |
| 81 | 84 | action: 'resolve from binding', |
@@ -105,7 +108,9 @@ discard block |
||
| 105 | 108 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 106 | 109 | default => $binding, |
| 107 | 110 | }; |
| 108 | - } finally { |
|
| 111 | + } |
|
| 112 | + finally |
|
| 113 | + { |
|
| 109 | 114 | $this->state->bindings[$alias] ??= $binding; |
| 110 | 115 | $this->tracer->pop(true); |
| 111 | 116 | $this->tracer->pop(false); |
@@ -119,18 +124,23 @@ discard block |
||
| 119 | 124 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
| 120 | 125 | { |
| 121 | 126 | $context = $ctx->context; |
| 122 | - try { |
|
| 127 | + try |
|
| 128 | + { |
|
| 123 | 129 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 124 | - } catch (\ReflectionException $e) { |
|
| 130 | + } |
|
| 131 | + catch (\ReflectionException $e) |
|
| 132 | + { |
|
| 125 | 133 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 126 | 134 | } |
| 127 | 135 | |
| 128 | 136 | $injector = $binding->injector; |
| 129 | 137 | |
| 130 | - try { |
|
| 138 | + try |
|
| 139 | + { |
|
| 131 | 140 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 132 | 141 | |
| 133 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 142 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 143 | + { |
|
| 134 | 144 | throw new InjectionException( |
| 135 | 145 | \sprintf( |
| 136 | 146 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -157,7 +167,8 @@ discard block |
||
| 157 | 167 | default => (string)$context, |
| 158 | 168 | }); |
| 159 | 169 | |
| 160 | - if (!$reflection->isInstance($instance)) { |
|
| 170 | + if (!$reflection->isInstance($instance)) |
|
| 171 | + { |
|
| 161 | 172 | throw new InjectionException( |
| 162 | 173 | \sprintf( |
| 163 | 174 | "Invalid injection response for '%s'.", |
@@ -167,7 +178,9 @@ discard block |
||
| 167 | 178 | } |
| 168 | 179 | |
| 169 | 180 | return $instance; |
| 170 | - } finally { |
|
| 181 | + } |
|
| 182 | + finally |
|
| 183 | + { |
|
| 171 | 184 | $this->state->bindings[$ctx->class] ??= $binding; |
| 172 | 185 | } |
| 173 | 186 | } |
@@ -186,7 +199,8 @@ discard block |
||
| 186 | 199 | //Binding is pointing to something else |
| 187 | 200 | : $this->make($binding->alias, $arguments, $context); |
| 188 | 201 | |
| 189 | - if ($binding->singleton && $arguments === []) { |
|
| 202 | + if ($binding->singleton && $arguments === []) |
|
| 203 | + { |
|
| 190 | 204 | $this->state->singletons[$alias] = $result; |
| 191 | 205 | } |
| 192 | 206 | |
@@ -201,7 +215,8 @@ discard block |
||
| 201 | 215 | ): mixed { |
| 202 | 216 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 203 | 217 | |
| 204 | - if ($binding->singleton && $arguments === []) { |
|
| 218 | + if ($binding->singleton && $arguments === []) |
|
| 219 | + { |
|
| 205 | 220 | $this->state->singletons[$alias] = $result; |
| 206 | 221 | } |
| 207 | 222 | |
@@ -242,11 +257,14 @@ discard block |
||
| 242 | 257 | array $arguments, |
| 243 | 258 | ): mixed { |
| 244 | 259 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 245 | - try { |
|
| 260 | + try |
|
| 261 | + { |
|
| 246 | 262 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 247 | 263 | ? ($binding->factory)() |
| 248 | 264 | : $this->invoker->invoke($binding->factory, $arguments); |
| 249 | - } catch (NotCallableException $e) { |
|
| 265 | + } |
|
| 266 | + catch (NotCallableException $e) |
|
| 267 | + { |
|
| 250 | 268 | throw new ContainerException( |
| 251 | 269 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 252 | 270 | $e->getCode(), |
@@ -265,19 +283,24 @@ discard block |
||
| 265 | 283 | ): ?object { |
| 266 | 284 | $avoidCache = $arguments !== []; |
| 267 | 285 | |
| 268 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 269 | - try { |
|
| 286 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 287 | + { |
|
| 288 | + try |
|
| 289 | + { |
|
| 270 | 290 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 271 | 291 | |
| 272 | 292 | $object = $this->createInstance( |
| 273 | 293 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 274 | 294 | $arguments, |
| 275 | 295 | ); |
| 276 | - if ($avoidCache) { |
|
| 296 | + if ($avoidCache) |
|
| 297 | + { |
|
| 277 | 298 | return $object; |
| 278 | 299 | } |
| 279 | 300 | $binding->reference = WeakReference::create($object); |
| 280 | - } catch (\Throwable) { |
|
| 301 | + } |
|
| 302 | + catch (\Throwable) |
|
| 303 | + { |
|
| 281 | 304 | throw new ContainerException( |
| 282 | 305 | $this->tracer->combineTraceMessage( |
| 283 | 306 | \sprintf( |
@@ -287,7 +310,9 @@ discard block |
||
| 287 | 310 | ) |
| 288 | 311 | ) |
| 289 | 312 | ); |
| 290 | - } finally { |
|
| 313 | + } |
|
| 314 | + finally |
|
| 315 | + { |
|
| 291 | 316 | $this->tracer->pop(); |
| 292 | 317 | } |
| 293 | 318 | } |
@@ -302,19 +327,26 @@ discard block |
||
| 302 | 327 | ): mixed { |
| 303 | 328 | $parent = $this->scope->getParentFactory(); |
| 304 | 329 | |
| 305 | - if ($parent !== null) { |
|
| 306 | - try { |
|
| 330 | + if ($parent !== null) |
|
| 331 | + { |
|
| 332 | + try |
|
| 333 | + { |
|
| 307 | 334 | $this->tracer->push(false, ...[ |
| 308 | 335 | 'current scope' => $this->scope->getScopeName(), |
| 309 | 336 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 310 | 337 | ]); |
| 311 | 338 | /** @psalm-suppress TooManyArguments */ |
| 312 | 339 | return $parent->make($alias, $parameters, $context); |
| 313 | - } catch (BadScopeException $e) { |
|
| 314 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 340 | + } |
|
| 341 | + catch (BadScopeException $e) |
|
| 342 | + { |
|
| 343 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
| 344 | + { |
|
| 315 | 345 | throw $e; |
| 316 | 346 | } |
| 317 | - } catch (ContainerExceptionInterface $e) { |
|
| 347 | + } |
|
| 348 | + catch (ContainerExceptionInterface $e) |
|
| 349 | + { |
|
| 318 | 350 | $className = match (true) { |
| 319 | 351 | $e instanceof NotFoundException => NotFoundException::class, |
| 320 | 352 | default => ContainerException::class, |
@@ -323,19 +355,24 @@ discard block |
||
| 323 | 355 | 'Can\'t resolve `%s`.', |
| 324 | 356 | $alias, |
| 325 | 357 | )), previous: $e); |
| 326 | - } finally { |
|
| 358 | + } |
|
| 359 | + finally |
|
| 360 | + { |
|
| 327 | 361 | $this->tracer->pop(false); |
| 328 | 362 | } |
| 329 | 363 | } |
| 330 | 364 | |
| 331 | 365 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 332 | - try { |
|
| 366 | + try |
|
| 367 | + { |
|
| 333 | 368 | //No direct instructions how to construct class, make is automatically |
| 334 | 369 | return $this->autowire( |
| 335 | 370 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 336 | 371 | $parameters, |
| 337 | 372 | ); |
| 338 | - } finally { |
|
| 373 | + } |
|
| 374 | + finally |
|
| 375 | + { |
|
| 339 | 376 | $this->tracer->pop(false); |
| 340 | 377 | } |
| 341 | 378 | } |
@@ -385,7 +422,8 @@ discard block |
||
| 385 | 422 | // Check scope name |
| 386 | 423 | $ctx->reflection = new \ReflectionClass($instance); |
| 387 | 424 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 388 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
| 425 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
| 426 | + { |
|
| 389 | 427 | throw new BadScopeException($scopeName, $instance::class); |
| 390 | 428 | } |
| 391 | 429 | |
@@ -412,24 +450,30 @@ discard block |
||
| 412 | 450 | array $arguments, |
| 413 | 451 | ): object { |
| 414 | 452 | $class = $ctx->class; |
| 415 | - try { |
|
| 453 | + try |
|
| 454 | + { |
|
| 416 | 455 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 417 | - } catch (\ReflectionException $e) { |
|
| 456 | + } |
|
| 457 | + catch (\ReflectionException $e) |
|
| 458 | + { |
|
| 418 | 459 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 419 | 460 | } |
| 420 | 461 | |
| 421 | 462 | // Check scope name |
| 422 | 463 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 423 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 464 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
| 465 | + { |
|
| 424 | 466 | throw new BadScopeException($scope, $class); |
| 425 | 467 | } |
| 426 | 468 | |
| 427 | 469 | // We have to construct class using external injector when we know the exact context |
| 428 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 470 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
| 471 | + { |
|
| 429 | 472 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 430 | 473 | } |
| 431 | 474 | |
| 432 | - if (!$reflection->isInstantiable()) { |
|
| 475 | + if (!$reflection->isInstantiable()) |
|
| 476 | + { |
|
| 433 | 477 | $itIs = match (true) { |
| 434 | 478 | $reflection->isEnum() => 'Enum', |
| 435 | 479 | $reflection->isAbstract() => 'Abstract class', |
@@ -442,12 +486,16 @@ discard block |
||
| 442 | 486 | |
| 443 | 487 | $constructor = $reflection->getConstructor(); |
| 444 | 488 | |
| 445 | - if ($constructor !== null) { |
|
| 446 | - try { |
|
| 489 | + if ($constructor !== null) |
|
| 490 | + { |
|
| 491 | + try |
|
| 492 | + { |
|
| 447 | 493 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 448 | 494 | $this->tracer->push(true); |
| 449 | 495 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
| 450 | - } catch (ValidationException $e) { |
|
| 496 | + } |
|
| 497 | + catch (ValidationException $e) |
|
| 498 | + { |
|
| 451 | 499 | throw new ContainerException( |
| 452 | 500 | $this->tracer->combineTraceMessage( |
| 453 | 501 | \sprintf( |
@@ -457,22 +505,31 @@ discard block |
||
| 457 | 505 | ) |
| 458 | 506 | ), |
| 459 | 507 | ); |
| 460 | - } finally { |
|
| 508 | + } |
|
| 509 | + finally |
|
| 510 | + { |
|
| 461 | 511 | $this->tracer->pop(true); |
| 462 | 512 | $this->tracer->pop(false); |
| 463 | 513 | } |
| 464 | - try { |
|
| 514 | + try |
|
| 515 | + { |
|
| 465 | 516 | // Using constructor with resolved arguments |
| 466 | 517 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 467 | 518 | $this->tracer->push(true); |
| 468 | 519 | $instance = new $class(...$args); |
| 469 | - } catch (\TypeError $e) { |
|
| 520 | + } |
|
| 521 | + catch (\TypeError $e) |
|
| 522 | + { |
|
| 470 | 523 | throw new WrongTypeException($constructor, $e); |
| 471 | - } finally { |
|
| 524 | + } |
|
| 525 | + finally |
|
| 526 | + { |
|
| 472 | 527 | $this->tracer->pop(true); |
| 473 | 528 | $this->tracer->pop(false); |
| 474 | 529 | } |
| 475 | - } else { |
|
| 530 | + } |
|
| 531 | + else |
|
| 532 | + { |
|
| 476 | 533 | // No constructor specified |
| 477 | 534 | $instance = $reflection->newInstance(); |
| 478 | 535 | } |
@@ -490,13 +547,15 @@ discard block |
||
| 490 | 547 | $instance = $this->runInflector($instance); |
| 491 | 548 | |
| 492 | 549 | //Declarative singletons |
| 493 | - if ($this->isSingleton($ctx)) { |
|
| 550 | + if ($this->isSingleton($ctx)) |
|
| 551 | + { |
|
| 494 | 552 | $this->state->singletons[$ctx->alias] = $instance; |
| 495 | 553 | } |
| 496 | 554 | |
| 497 | 555 | // Register finalizer |
| 498 | 556 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 499 | - if ($finalizer !== null) { |
|
| 557 | + if ($finalizer !== null) |
|
| 558 | + { |
|
| 500 | 559 | $this->state->finalizers[] = $finalizer; |
| 501 | 560 | } |
| 502 | 561 | |
@@ -508,12 +567,14 @@ discard block |
||
| 508 | 567 | */ |
| 509 | 568 | private function isSingleton(Ctx $ctx): bool |
| 510 | 569 | { |
| 511 | - if ($ctx->singleton === true) { |
|
| 570 | + if ($ctx->singleton === true) |
|
| 571 | + { |
|
| 512 | 572 | return true; |
| 513 | 573 | } |
| 514 | 574 | |
| 515 | 575 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 516 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 576 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 577 | + { |
|
| 517 | 578 | return true; |
| 518 | 579 | } |
| 519 | 580 | |
@@ -527,7 +588,8 @@ discard block |
||
| 527 | 588 | * @var Attribute\Finalize|null $attribute |
| 528 | 589 | */ |
| 529 | 590 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 530 | - if ($attribute === null) { |
|
| 591 | + if ($attribute === null) |
|
| 592 | + { |
|
| 531 | 593 | return null; |
| 532 | 594 | } |
| 533 | 595 | |
@@ -541,10 +603,14 @@ discard block |
||
| 541 | 603 | { |
| 542 | 604 | $scope = $this->scope; |
| 543 | 605 | |
| 544 | - while ($scope !== null) { |
|
| 545 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 546 | - if ($instance instanceof $class) { |
|
| 547 | - foreach ($inflectors as $inflector) { |
|
| 606 | + while ($scope !== null) |
|
| 607 | + { |
|
| 608 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 609 | + { |
|
| 610 | + if ($instance instanceof $class) |
|
| 611 | + { |
|
| 612 | + foreach ($inflectors as $inflector) |
|
| 613 | + { |
|
| 548 | 614 | $instance = $inflector->getParametersCount() > 1 |
| 549 | 615 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 550 | 616 | : ($inflector->inflector)($instance); |
@@ -560,9 +626,12 @@ discard block |
||
| 560 | 626 | |
| 561 | 627 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 562 | 628 | { |
| 563 | - try { |
|
| 629 | + try |
|
| 630 | + { |
|
| 564 | 631 | $this->resolver->validateArguments($reflection, $arguments); |
| 565 | - } catch (\Throwable) { |
|
| 632 | + } |
|
| 633 | + catch (\Throwable) |
|
| 634 | + { |
|
| 566 | 635 | return false; |
| 567 | 636 | } |
| 568 | 637 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | protected readonly string $interface, |
| 14 | 14 | public readonly bool $singleton = false, |
| 15 | - ) { |
|
| 15 | + ){ |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function __toString(): string |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | public function __construct( |
| 13 | 13 | string $interface, |
| 14 | 14 | bool $singleton = false, |
| 15 | - private readonly string|\BackedEnum|null $scope = null, |
|
| 15 | + private readonly string | \BackedEnum | null $scope = null, |
|
| 16 | 16 | private readonly ?string $version = null, |
| 17 | 17 | private readonly ?string $message = null, |
| 18 | - ) { |
|
| 19 | - if (($scope === null || $version === null) && $message === null) { |
|
| 18 | + ){ |
|
| 19 | + if (($scope === null || $version === null) && $message === null){ |
|
| 20 | 20 | throw new \InvalidArgumentException('Scope and version or custom message must be provided.'); |
| 21 | 21 | } |
| 22 | 22 | |
@@ -16,7 +16,8 @@ |
||
| 16 | 16 | private readonly ?string $version = null, |
| 17 | 17 | private readonly ?string $message = null, |
| 18 | 18 | ) { |
| 19 | - if (($scope === null || $version === null) && $message === null) { |
|
| 19 | + if (($scope === null || $version === null) && $message === null) |
|
| 20 | + { |
|
| 20 | 21 | throw new \InvalidArgumentException('Scope and version or custom message must be provided.'); |
| 21 | 22 | } |
| 22 | 23 | |