@@ -13,7 +13,8 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | public function __construct( |
| 15 | 15 | private readonly ContainerInterface $container, |
| 16 | - ) {} |
|
| 16 | + ) { |
|
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | /** |
| 19 | 20 | * @psalm-suppress InvalidReturnType |
@@ -26,7 +27,8 @@ discard block |
||
| 26 | 27 | |
| 27 | 28 | $context = $tracer->getContext(); |
| 28 | 29 | |
| 29 | - if (!empty($context)) { |
|
| 30 | + if (!empty($context)) |
|
| 31 | + { |
|
| 30 | 32 | $record['extra']['telemetry'] = $context; |
| 31 | 33 | } |
| 32 | 34 | |
@@ -33,7 +33,8 @@ |
||
| 33 | 33 | |
| 34 | 34 | public function __construct( |
| 35 | 35 | private readonly ConfiguratorInterface $config, |
| 36 | - ) {} |
|
| 36 | + ) { |
|
| 37 | +} |
|
| 37 | 38 | |
| 38 | 39 | public function init(BinderInterface $binder, EnvironmentInterface $env): void |
| 39 | 40 | { |
@@ -68,17 +68,20 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
| 70 | 70 | { |
| 71 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 71 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
| 72 | + { |
|
| 72 | 73 | return $this->state->singletons[$alias]; |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | 76 | $binding = $this->state->bindings[$alias] ?? null; |
| 76 | 77 | |
| 77 | - if ($binding === null) { |
|
| 78 | + if ($binding === null) |
|
| 79 | + { |
|
| 78 | 80 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | - try { |
|
| 83 | + try |
|
| 84 | + { |
|
| 82 | 85 | $this->tracer->push( |
| 83 | 86 | false, |
| 84 | 87 | action: 'resolve from binding', |
@@ -108,7 +111,9 @@ discard block |
||
| 108 | 111 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 109 | 112 | default => $binding, |
| 110 | 113 | }; |
| 111 | - } finally { |
|
| 114 | + } |
|
| 115 | + finally |
|
| 116 | + { |
|
| 112 | 117 | $this->state->bindings[$alias] ??= $binding; |
| 113 | 118 | $this->tracer->pop(true); |
| 114 | 119 | $this->tracer->pop(false); |
@@ -122,18 +127,23 @@ discard block |
||
| 122 | 127 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
| 123 | 128 | { |
| 124 | 129 | $context = $ctx->context; |
| 125 | - try { |
|
| 130 | + try |
|
| 131 | + { |
|
| 126 | 132 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 127 | - } catch (\ReflectionException $e) { |
|
| 133 | + } |
|
| 134 | + catch (\ReflectionException $e) |
|
| 135 | + { |
|
| 128 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 129 | 137 | } |
| 130 | 138 | |
| 131 | 139 | $injector = $binding->injector; |
| 132 | 140 | |
| 133 | - try { |
|
| 141 | + try |
|
| 142 | + { |
|
| 134 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 135 | 144 | |
| 136 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 146 | + { |
|
| 137 | 147 | throw new InjectionException( |
| 138 | 148 | \sprintf( |
| 139 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -160,7 +170,8 @@ discard block |
||
| 160 | 170 | default => (string) $context, |
| 161 | 171 | }); |
| 162 | 172 | |
| 163 | - if (!$reflection->isInstance($instance)) { |
|
| 173 | + if (!$reflection->isInstance($instance)) |
|
| 174 | + { |
|
| 164 | 175 | throw new InjectionException( |
| 165 | 176 | \sprintf( |
| 166 | 177 | "Invalid injection response for '%s'.", |
@@ -170,7 +181,9 @@ discard block |
||
| 170 | 181 | } |
| 171 | 182 | |
| 172 | 183 | return $instance; |
| 173 | - } finally { |
|
| 184 | + } |
|
| 185 | + finally |
|
| 186 | + { |
|
| 174 | 187 | $this->state->bindings[$ctx->class] ??= $binding; |
| 175 | 188 | } |
| 176 | 189 | } |
@@ -189,7 +202,8 @@ discard block |
||
| 189 | 202 | //Binding is pointing to something else |
| 190 | 203 | : $this->make($binding->alias, $arguments, $context); |
| 191 | 204 | |
| 192 | - if ($binding->singleton && $arguments === []) { |
|
| 205 | + if ($binding->singleton && $arguments === []) |
|
| 206 | + { |
|
| 193 | 207 | $this->state->singletons[$alias] = $result; |
| 194 | 208 | } |
| 195 | 209 | |
@@ -198,7 +212,8 @@ discard block |
||
| 198 | 212 | |
| 199 | 213 | private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
| 200 | 214 | { |
| 201 | - if ($context instanceof RetryContext) { |
|
| 215 | + if ($context instanceof RetryContext) |
|
| 216 | + { |
|
| 202 | 217 | return $binding->fallbackFactory === null |
| 203 | 218 | ? throw new RecursiveProxyException( |
| 204 | 219 | $alias, |
@@ -209,7 +224,8 @@ discard block |
||
| 209 | 224 | |
| 210 | 225 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 211 | 226 | |
| 212 | - if ($binding->singleton) { |
|
| 227 | + if ($binding->singleton) |
|
| 228 | + { |
|
| 213 | 229 | $this->state->singletons[$alias] = $result; |
| 214 | 230 | } |
| 215 | 231 | |
@@ -224,14 +240,16 @@ discard block |
||
| 224 | 240 | ): object { |
| 225 | 241 | $avoidCache = $arguments !== []; |
| 226 | 242 | |
| 227 | - if ($avoidCache) { |
|
| 243 | + if ($avoidCache) |
|
| 244 | + { |
|
| 228 | 245 | return $this->createInstance( |
| 229 | 246 | new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
| 230 | 247 | $arguments, |
| 231 | 248 | ); |
| 232 | 249 | } |
| 233 | 250 | |
| 234 | - if ($binding->singleton) { |
|
| 251 | + if ($binding->singleton) |
|
| 252 | + { |
|
| 235 | 253 | $this->state->singletons[$alias] = $binding->value; |
| 236 | 254 | } |
| 237 | 255 | |
@@ -261,11 +279,14 @@ discard block |
||
| 261 | 279 | array $arguments, |
| 262 | 280 | ): mixed { |
| 263 | 281 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 264 | - try { |
|
| 282 | + try |
|
| 283 | + { |
|
| 265 | 284 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 266 | 285 | ? ($binding->factory)() |
| 267 | 286 | : $this->invoker->invoke($binding->factory, $arguments); |
| 268 | - } catch (NotCallableException $e) { |
|
| 287 | + } |
|
| 288 | + catch (NotCallableException $e) |
|
| 289 | + { |
|
| 269 | 290 | throw new ContainerException( |
| 270 | 291 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 271 | 292 | $e->getCode(), |
@@ -284,19 +305,24 @@ discard block |
||
| 284 | 305 | ): ?object { |
| 285 | 306 | $avoidCache = $arguments !== []; |
| 286 | 307 | |
| 287 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 288 | - try { |
|
| 308 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 309 | + { |
|
| 310 | + try |
|
| 311 | + { |
|
| 289 | 312 | $this->tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
| 290 | 313 | |
| 291 | 314 | $object = $this->createInstance( |
| 292 | 315 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 293 | 316 | $arguments, |
| 294 | 317 | ); |
| 295 | - if ($avoidCache) { |
|
| 318 | + if ($avoidCache) |
|
| 319 | + { |
|
| 296 | 320 | return $object; |
| 297 | 321 | } |
| 298 | 322 | $binding->reference = \WeakReference::create($object); |
| 299 | - } catch (\Throwable) { |
|
| 323 | + } |
|
| 324 | + catch (\Throwable) |
|
| 325 | + { |
|
| 300 | 326 | throw new ContainerException( |
| 301 | 327 | $this->tracer->combineTraceMessage( |
| 302 | 328 | \sprintf( |
@@ -306,7 +332,9 @@ discard block |
||
| 306 | 332 | ), |
| 307 | 333 | ), |
| 308 | 334 | ); |
| 309 | - } finally { |
|
| 335 | + } |
|
| 336 | + finally |
|
| 337 | + { |
|
| 310 | 338 | $this->tracer->pop(); |
| 311 | 339 | } |
| 312 | 340 | } |
@@ -321,19 +349,26 @@ discard block |
||
| 321 | 349 | ): mixed { |
| 322 | 350 | $parent = $this->scope->getParentFactory(); |
| 323 | 351 | |
| 324 | - if ($parent !== null) { |
|
| 325 | - try { |
|
| 352 | + if ($parent !== null) |
|
| 353 | + { |
|
| 354 | + try |
|
| 355 | + { |
|
| 326 | 356 | $this->tracer->push(false, ...[ |
| 327 | 357 | 'current scope' => $this->scope->getScopeName(), |
| 328 | 358 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 329 | 359 | ]); |
| 330 | 360 | /** @psalm-suppress TooManyArguments */ |
| 331 | 361 | return $parent->make($alias, $parameters, $context); |
| 332 | - } catch (BadScopeException $e) { |
|
| 333 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 362 | + } |
|
| 363 | + catch (BadScopeException $e) |
|
| 364 | + { |
|
| 365 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
| 366 | + { |
|
| 334 | 367 | throw $e; |
| 335 | 368 | } |
| 336 | - } catch (ContainerExceptionInterface $e) { |
|
| 369 | + } |
|
| 370 | + catch (ContainerExceptionInterface $e) |
|
| 371 | + { |
|
| 337 | 372 | $className = match (true) { |
| 338 | 373 | $e instanceof RecursiveProxyException => throw $e, |
| 339 | 374 | $e instanceof NotFoundExceptionInterface => NotFoundException::class, |
@@ -343,19 +378,24 @@ discard block |
||
| 343 | 378 | 'Can\'t resolve `%s`.', |
| 344 | 379 | $alias, |
| 345 | 380 | )), previous: $e); |
| 346 | - } finally { |
|
| 381 | + } |
|
| 382 | + finally |
|
| 383 | + { |
|
| 347 | 384 | $this->tracer->pop(false); |
| 348 | 385 | } |
| 349 | 386 | } |
| 350 | 387 | |
| 351 | 388 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 352 | - try { |
|
| 389 | + try |
|
| 390 | + { |
|
| 353 | 391 | //No direct instructions how to construct class, make is automatically |
| 354 | 392 | return $this->autowire( |
| 355 | 393 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 356 | 394 | $parameters, |
| 357 | 395 | ); |
| 358 | - } finally { |
|
| 396 | + } |
|
| 397 | + finally |
|
| 398 | + { |
|
| 359 | 399 | $this->tracer->pop(false); |
| 360 | 400 | } |
| 361 | 401 | } |
@@ -402,13 +442,16 @@ discard block |
||
| 402 | 442 | Ctx $ctx, |
| 403 | 443 | array $arguments, |
| 404 | 444 | ): object { |
| 405 | - if ($this->options->checkScope) { |
|
| 445 | + if ($this->options->checkScope) |
|
| 446 | + { |
|
| 406 | 447 | // Check scope name |
| 407 | 448 | $ctx->reflection = new \ReflectionClass($instance); |
| 408 | 449 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 409 | - if ($scopeName !== null) { |
|
| 450 | + if ($scopeName !== null) |
|
| 451 | + { |
|
| 410 | 452 | $scope = $this->scope; |
| 411 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 453 | + while ($scope->getScopeName() !== $scopeName) |
|
| 454 | + { |
|
| 412 | 455 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 413 | 456 | } |
| 414 | 457 | } |
@@ -437,26 +480,33 @@ discard block |
||
| 437 | 480 | array $arguments, |
| 438 | 481 | ): object { |
| 439 | 482 | $class = $ctx->class; |
| 440 | - try { |
|
| 483 | + try |
|
| 484 | + { |
|
| 441 | 485 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 442 | - } catch (\ReflectionException $e) { |
|
| 486 | + } |
|
| 487 | + catch (\ReflectionException $e) |
|
| 488 | + { |
|
| 443 | 489 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 444 | 490 | } |
| 445 | 491 | |
| 446 | 492 | // Check scope name |
| 447 | - if ($this->options->checkScope) { |
|
| 493 | + if ($this->options->checkScope) |
|
| 494 | + { |
|
| 448 | 495 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 449 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 496 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
| 497 | + { |
|
| 450 | 498 | throw new BadScopeException($scope, $class); |
| 451 | 499 | } |
| 452 | 500 | } |
| 453 | 501 | |
| 454 | 502 | // We have to construct class using external injector when we know the exact context |
| 455 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 503 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
| 504 | + { |
|
| 456 | 505 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 457 | 506 | } |
| 458 | 507 | |
| 459 | - if (!$reflection->isInstantiable()) { |
|
| 508 | + if (!$reflection->isInstantiable()) |
|
| 509 | + { |
|
| 460 | 510 | $itIs = match (true) { |
| 461 | 511 | $reflection->isEnum() => 'Enum', |
| 462 | 512 | $reflection->isAbstract() => 'Abstract class', |
@@ -469,12 +519,16 @@ discard block |
||
| 469 | 519 | |
| 470 | 520 | $constructor = $reflection->getConstructor(); |
| 471 | 521 | |
| 472 | - if ($constructor !== null) { |
|
| 473 | - try { |
|
| 522 | + if ($constructor !== null) |
|
| 523 | + { |
|
| 524 | + try |
|
| 525 | + { |
|
| 474 | 526 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 475 | 527 | $this->tracer->push(true); |
| 476 | 528 | $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments); |
| 477 | - } catch (ValidationException $e) { |
|
| 529 | + } |
|
| 530 | + catch (ValidationException $e) |
|
| 531 | + { |
|
| 478 | 532 | throw new ContainerException( |
| 479 | 533 | $this->tracer->combineTraceMessage( |
| 480 | 534 | \sprintf( |
@@ -484,22 +538,31 @@ discard block |
||
| 484 | 538 | ), |
| 485 | 539 | ), |
| 486 | 540 | ); |
| 487 | - } finally { |
|
| 541 | + } |
|
| 542 | + finally |
|
| 543 | + { |
|
| 488 | 544 | $this->tracer->pop(true); |
| 489 | 545 | $this->tracer->pop(false); |
| 490 | 546 | } |
| 491 | - try { |
|
| 547 | + try |
|
| 548 | + { |
|
| 492 | 549 | // Using constructor with resolved arguments |
| 493 | 550 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 494 | 551 | $this->tracer->push(true); |
| 495 | 552 | $instance = new $class(...$args); |
| 496 | - } catch (\TypeError $e) { |
|
| 553 | + } |
|
| 554 | + catch (\TypeError $e) |
|
| 555 | + { |
|
| 497 | 556 | throw new WrongTypeException($constructor, $e); |
| 498 | - } finally { |
|
| 557 | + } |
|
| 558 | + finally |
|
| 559 | + { |
|
| 499 | 560 | $this->tracer->pop(true); |
| 500 | 561 | $this->tracer->pop(false); |
| 501 | 562 | } |
| 502 | - } else { |
|
| 563 | + } |
|
| 564 | + else |
|
| 565 | + { |
|
| 503 | 566 | // No constructor specified |
| 504 | 567 | $instance = $reflection->newInstance(); |
| 505 | 568 | } |
@@ -517,13 +580,15 @@ discard block |
||
| 517 | 580 | $instance = $this->runInflector($instance); |
| 518 | 581 | |
| 519 | 582 | //Declarative singletons |
| 520 | - if ($this->isSingleton($ctx)) { |
|
| 583 | + if ($this->isSingleton($ctx)) |
|
| 584 | + { |
|
| 521 | 585 | $this->state->singletons[$ctx->alias] = $instance; |
| 522 | 586 | } |
| 523 | 587 | |
| 524 | 588 | // Register finalizer |
| 525 | 589 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 526 | - if ($finalizer !== null) { |
|
| 590 | + if ($finalizer !== null) |
|
| 591 | + { |
|
| 527 | 592 | $this->state->finalizers[] = $finalizer; |
| 528 | 593 | } |
| 529 | 594 | |
@@ -535,12 +600,14 @@ discard block |
||
| 535 | 600 | */ |
| 536 | 601 | private function isSingleton(Ctx $ctx): bool |
| 537 | 602 | { |
| 538 | - if ($ctx->singleton === true) { |
|
| 603 | + if ($ctx->singleton === true) |
|
| 604 | + { |
|
| 539 | 605 | return true; |
| 540 | 606 | } |
| 541 | 607 | |
| 542 | 608 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 543 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 609 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 610 | + { |
|
| 544 | 611 | return true; |
| 545 | 612 | } |
| 546 | 613 | |
@@ -554,7 +621,8 @@ discard block |
||
| 554 | 621 | * @var Attribute\Finalize|null $attribute |
| 555 | 622 | */ |
| 556 | 623 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 557 | - if ($attribute === null) { |
|
| 624 | + if ($attribute === null) |
|
| 625 | + { |
|
| 558 | 626 | return null; |
| 559 | 627 | } |
| 560 | 628 | |
@@ -568,10 +636,14 @@ discard block |
||
| 568 | 636 | { |
| 569 | 637 | $scope = $this->scope; |
| 570 | 638 | |
| 571 | - while ($scope !== null) { |
|
| 572 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 573 | - if ($instance instanceof $class) { |
|
| 574 | - foreach ($inflectors as $inflector) { |
|
| 639 | + while ($scope !== null) |
|
| 640 | + { |
|
| 641 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 642 | + { |
|
| 643 | + if ($instance instanceof $class) |
|
| 644 | + { |
|
| 645 | + foreach ($inflectors as $inflector) |
|
| 646 | + { |
|
| 575 | 647 | $instance = $inflector->getParametersCount() > 1 |
| 576 | 648 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 577 | 649 | : ($inflector->inflector)($instance); |
@@ -587,9 +659,12 @@ discard block |
||
| 587 | 659 | |
| 588 | 660 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 589 | 661 | { |
| 590 | - try { |
|
| 662 | + try |
|
| 663 | + { |
|
| 591 | 664 | $this->resolver->validateArguments($reflection, $arguments); |
| 592 | - } catch (\Throwable) { |
|
| 665 | + } |
|
| 666 | + catch (\Throwable) |
|
| 667 | + { |
|
| 593 | 668 | return false; |
| 594 | 669 | } |
| 595 | 670 | |
@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ?ScopeInterface $scope = new Container(), |
| 23 | - ) {} |
|
| 23 | + ) { |
|
| 24 | +} |
|
| 24 | 25 | |
| 25 | 26 | /** |
| 26 | 27 | * @throws \Throwable |
@@ -28,18 +29,22 @@ discard block |
||
| 28 | 29 | final protected function runScope(SpanInterface $span, callable $callback): mixed |
| 29 | 30 | { |
| 30 | 31 | $container = ContainerScope::getContainer(); |
| 31 | - if ($container === null) { |
|
| 32 | + if ($container === null) |
|
| 33 | + { |
|
| 32 | 34 | return $this->scope->runScope([ |
| 33 | 35 | SpanInterface::class => $span, |
| 34 | 36 | TracerInterface::class => $this, |
| 35 | 37 | ], static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback)); |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | - if ($container instanceof Container) { |
|
| 40 | + if ($container instanceof Container) |
|
| 41 | + { |
|
| 39 | 42 | $invoker = $container; |
| 40 | 43 | $binder = $container; |
| 41 | 44 | $scope = $container; |
| 42 | - } else { |
|
| 45 | + } |
|
| 46 | + else |
|
| 47 | + { |
|
| 43 | 48 | /** @var ScopeInterface $scope */ |
| 44 | 49 | $scope = $container->get(ScopeInterface::class); |
| 45 | 50 | /** @var InvokerInterface $invoker */ |
@@ -48,16 +53,20 @@ discard block |
||
| 48 | 53 | $binder = $container->get(BinderInterface::class); |
| 49 | 54 | } |
| 50 | 55 | |
| 51 | - try { |
|
| 56 | + try |
|
| 57 | + { |
|
| 52 | 58 | $prevSpan = $container->get(SpanInterface::class); |
| 53 | - } catch (\Throwable) { |
|
| 59 | + } |
|
| 60 | + catch (\Throwable) |
|
| 61 | + { |
|
| 54 | 62 | $prevSpan = null; |
| 55 | 63 | } |
| 56 | 64 | |
| 57 | 65 | /** @psalm-suppress TooManyArguments */ |
| 58 | 66 | $binder->bindSingleton(SpanInterface::class, $span, true); |
| 59 | 67 | |
| 60 | - try { |
|
| 68 | + try |
|
| 69 | + { |
|
| 61 | 70 | /** @psalm-suppress InvalidArgument */ |
| 62 | 71 | return $prevSpan === null |
| 63 | 72 | ? $scope->runScope( |
@@ -69,7 +78,9 @@ discard block |
||
| 69 | 78 | static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback), |
| 70 | 79 | ) |
| 71 | 80 | : $invoker->invoke($callback); |
| 72 | - } finally { |
|
| 81 | + } |
|
| 82 | + finally |
|
| 83 | + { |
|
| 73 | 84 | $prevSpan === null |
| 74 | 85 | ? $binder->removeBinding(SpanInterface::class) |
| 75 | 86 | : $binder->bindSingleton(SpanInterface::class, $prevSpan); |