Test Failed
Pull Request — master (#1082)
by Maxim
11:40
created
src/Core/tests/Internal/Common/RegistryTest.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,8 @@
 block discarded – undo
31 31
         $option->checkScope = true;
32 32
         yield [$option];
33 33
 
34
-        $option = new class extends Options {
34
+        $option = new class extends Options
35
+        {
35 36
             public int $customOption = 3;
36 37
         };
37 38
         $option->customOption = 5;
Please login to merge, or discard this patch.
src/Core/tests/Scope/ScopeAttributeTest.php 1 patch
Braces   +52 added lines, -25 removed lines patch added patch discarded remove patch
@@ -40,8 +40,10 @@  discard block
 block discarded – undo
40 40
     {
41 41
         $root = self::makeContainer();
42 42
 
43
-        $root->runScoped(static function (Container $c1) {
44
-            $c1->runScoped(static function (Container $c2) use ($c1) {
43
+        $root->runScoped(static function (Container $c1)
44
+        {
45
+            $c1->runScoped(static function (Container $c2) use ($c1)
46
+            {
45 47
                 $obj1 = $c1->get(AttrScopeFooSingleton::class);
46 48
                 $obj2 = $c2->get(AttrScopeFooSingleton::class);
47 49
 
@@ -55,8 +57,10 @@  discard block
 block discarded – undo
55 57
         $root = self::makeContainer();
56 58
         $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());
57 59
 
58
-        $root->runScoped(static function (Container $fooScope) {
59
-            $fooScope->runScoped(static function (Container $container) {
60
+        $root->runScoped(static function (Container $fooScope)
61
+        {
62
+            $fooScope->runScoped(static function (Container $container)
63
+            {
60 64
                 self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding'));
61 65
             }, name: 'bar');
62 66
         }, name: 'foo');
@@ -70,8 +74,10 @@  discard block
 block discarded – undo
70 74
         $root = self::makeContainer();
71 75
         $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());
72 76
 
73
-        $root->runScoped(static function (Container $fooScope) {
74
-            $fooScope->runScoped(static function (Container $container) {
77
+        $root->runScoped(static function (Container $fooScope)
78
+        {
79
+            $fooScope->runScoped(static function (Container $container)
80
+            {
75 81
                 $container->get('binding');
76 82
             }, name: 'bar');
77 83
         }, name: 'baz');
@@ -82,8 +88,10 @@  discard block
 block discarded – undo
82 88
         $root = self::makeContainer(false);
83 89
         $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo());
84 90
 
85
-        $root->runScoped(static function (Container $fooScope) {
86
-            $fooScope->runScoped(static function (Container $container) {
91
+        $root->runScoped(static function (Container $fooScope)
92
+        {
93
+            $fooScope->runScoped(static function (Container $container)
94
+            {
87 95
                 self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding'));
88 96
             }, name: 'bar');
89 97
         }, name: 'baz');
@@ -102,8 +110,10 @@  discard block
 block discarded – undo
102 110
         $root = self::makeContainer();
103 111
         $root->bind('foo', self::makeFooScopeObject(...));
104 112
 
105
-        $root->runScoped(static function (Container $c1) {
106
-            $c1->runScoped(static function (Container $c2) {
113
+        $root->runScoped(static function (Container $c1)
114
+        {
115
+            $c1->runScoped(static function (Container $c2)
116
+            {
107 117
                 $c2->get('foo');
108 118
             }, name: 'foo');
109 119
         });
@@ -115,8 +125,10 @@  discard block
 block discarded – undo
115 125
         $root = self::makeContainer(false);
116 126
         $root->bind('foo', self::makeFooScopeObject(...));
117 127
 
118
-        $root->runScoped(static function (Container $c1) {
119
-            $c1->runScoped(static function (Container $c2) {
128
+        $root->runScoped(static function (Container $c1)
129
+        {
130
+            $c1->runScoped(static function (Container $c2)
131
+            {
120 132
                 self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo'));
121 133
             }, name: 'foo');
122 134
         });
@@ -134,8 +146,10 @@  discard block
 block discarded – undo
134 146
         $root = self::makeContainer();
135 147
         $root->bind('foo', self::makeFooScopeObject(...));
136 148
 
137
-        $root->runScoped(static function (Container $c1) {
138
-            $c1->runScoped(static function (Container $c2) {
149
+        $root->runScoped(static function (Container $c1)
150
+        {
151
+            $c1->runScoped(static function (Container $c2)
152
+            {
139 153
                 $c2->get('foo');
140 154
             });
141 155
         });
@@ -147,8 +161,10 @@  discard block
 block discarded – undo
147 161
         $root = self::makeContainer(false);
148 162
         $root->bind('foo', self::makeFooScopeObject(...));
149 163
 
150
-        $root->runScoped(static function (Container $c1) {
151
-            $c1->runScoped(static function (Container $c2) {
164
+        $root->runScoped(static function (Container $c1)
165
+        {
166
+            $c1->runScoped(static function (Container $c2)
167
+            {
152 168
                 self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo'));
153 169
             });
154 170
         });
@@ -166,15 +182,21 @@  discard block
 block discarded – undo
166 182
 
167 183
         $root = self::makeContainer();
168 184
 
169
-        try {
170
-            $root->runScoped(static function (Container $c1) {
171
-                $c1->runScoped(static function (Container $c2) {
172
-                    $c2->runScoped(static function (Container $c3) {
185
+        try
186
+        {
187
+            $root->runScoped(static function (Container $c1)
188
+            {
189
+                $c1->runScoped(static function (Container $c2)
190
+                {
191
+                    $c2->runScoped(static function (Container $c3)
192
+                    {
173 193
                         // do nothing
174 194
                     }, name: 'root');
175 195
                 });
176 196
             });
177
-        } catch (NamedScopeDuplicationException $e) {
197
+        }
198
+        catch (NamedScopeDuplicationException $e)
199
+        {
178 200
             self::assertSame('root', $e->getScope());
179 201
             throw $e;
180 202
         }
@@ -189,14 +211,19 @@  discard block
 block discarded – undo
189 211
     {
190 212
         self::expectException(BadScopeException::class);
191 213
 
192
-        try {
214
+        try
215
+        {
193 216
             $root = self::makeContainer();
194
-            $root->runScoped(static function (Container $c1) {
195
-                $c1->runScoped(static function (Container $c2) {
217
+            $root->runScoped(static function (Container $c1)
218
+            {
219
+                $c1->runScoped(static function (Container $c2)
220
+                {
196 221
                     $c2->get(AttrScopeFoo::class);
197 222
                 });
198 223
             }, name: 'bar');
199
-        } catch (BadScopeException $e) {
224
+        }
225
+        catch (BadScopeException $e)
226
+        {
200 227
             self::assertSame('foo', $e->getScope());
201 228
             throw $e;
202 229
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 1 patch
Braces   +123 added lines, -53 removed lines patch added patch discarded remove patch
@@ -68,17 +68,20 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -200,7 +214,8 @@  discard block
 block discarded – undo
200 214
     {
201 215
         $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy());
202 216
 
203
-        if ($binding->singleton) {
217
+        if ($binding->singleton)
218
+        {
204 219
             $this->state->singletons[$alias] = $result;
205 220
         }
206 221
 
@@ -241,11 +256,14 @@  discard block
 block discarded – undo
241 256
         array $arguments,
242 257
     ): mixed {
243 258
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
244
-        try {
259
+        try
260
+        {
245 261
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
246 262
                 ? ($binding->factory)()
247 263
                 : $this->invoker->invoke($binding->factory, $arguments);
248
-        } catch (NotCallableException $e) {
264
+        }
265
+        catch (NotCallableException $e)
266
+        {
249 267
             throw new ContainerException(
250 268
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
251 269
                 $e->getCode(),
@@ -264,19 +282,24 @@  discard block
 block discarded – undo
264 282
     ): ?object {
265 283
         $avoidCache = $arguments !== [];
266 284
 
267
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
268
-            try {
285
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias))
286
+        {
287
+            try
288
+            {
269 289
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
270 290
 
271 291
                 $object = $this->createInstance(
272 292
                     new Ctx(alias: $alias, class: $alias, context: $context),
273 293
                     $arguments,
274 294
                 );
275
-                if ($avoidCache) {
295
+                if ($avoidCache)
296
+                {
276 297
                     return $object;
277 298
                 }
278 299
                 $binding->reference = WeakReference::create($object);
279
-            } catch (\Throwable) {
300
+            }
301
+            catch (\Throwable)
302
+            {
280 303
                 throw new ContainerException(
281 304
                     $this->tracer->combineTraceMessage(
282 305
                         \sprintf(
@@ -286,7 +309,9 @@  discard block
 block discarded – undo
286 309
                         )
287 310
                     )
288 311
                 );
289
-            } finally {
312
+            }
313
+            finally
314
+            {
290 315
                 $this->tracer->pop();
291 316
             }
292 317
         }
@@ -301,19 +326,26 @@  discard block
 block discarded – undo
301 326
     ): mixed {
302 327
         $parent = $this->scope->getParentFactory();
303 328
 
304
-        if ($parent !== null) {
305
-            try {
329
+        if ($parent !== null)
330
+        {
331
+            try
332
+            {
306 333
                 $this->tracer->push(false, ...[
307 334
                     'current scope' => $this->scope->getScopeName(),
308 335
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
309 336
                 ]);
310 337
                 /** @psalm-suppress TooManyArguments */
311 338
                 return $parent->make($alias, $parameters, $context);
312
-            } catch (BadScopeException $e) {
313
-                if ($this->scope->getScopeName() !== $e->getScope()) {
339
+            }
340
+            catch (BadScopeException $e)
341
+            {
342
+                if ($this->scope->getScopeName() !== $e->getScope())
343
+                {
314 344
                     throw $e;
315 345
                 }
316
-            } catch (ContainerExceptionInterface $e) {
346
+            }
347
+            catch (ContainerExceptionInterface $e)
348
+            {
317 349
                 $className = match (true) {
318 350
                     $e instanceof NotFoundException => NotFoundException::class,
319 351
                     default => ContainerException::class,
@@ -322,19 +354,24 @@  discard block
 block discarded – undo
322 354
                     'Can\'t resolve `%s`.',
323 355
                     $alias,
324 356
                 )), previous: $e);
325
-            } finally {
357
+            }
358
+            finally
359
+            {
326 360
                 $this->tracer->pop(false);
327 361
             }
328 362
         }
329 363
 
330 364
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
331
-        try {
365
+        try
366
+        {
332 367
             //No direct instructions how to construct class, make is automatically
333 368
             return $this->autowire(
334 369
                 new Ctx(alias: $alias, class: $alias, context: $context),
335 370
                 $parameters,
336 371
             );
337
-        } finally {
372
+        }
373
+        finally
374
+        {
338 375
             $this->tracer->pop(false);
339 376
         }
340 377
     }
@@ -384,9 +421,11 @@  discard block
 block discarded – undo
384 421
         // Check scope name
385 422
         $ctx->reflection = new \ReflectionClass($instance);
386 423
         $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
387
-        if ($scopeName !== null && $this->options->checkScope) {
424
+        if ($scopeName !== null && $this->options->checkScope)
425
+        {
388 426
             $scope = $this->scope;
389
-            while ($scope->getScopeName() !== $scopeName) {
427
+            while ($scope->getScopeName() !== $scopeName)
428
+            {
390 429
                 $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
391 430
             }
392 431
         }
@@ -414,24 +453,30 @@  discard block
 block discarded – undo
414 453
         array $arguments,
415 454
     ): object {
416 455
         $class = $ctx->class;
417
-        try {
456
+        try
457
+        {
418 458
             $ctx->reflection = $reflection = new \ReflectionClass($class);
419
-        } catch (\ReflectionException $e) {
459
+        }
460
+        catch (\ReflectionException $e)
461
+        {
420 462
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
421 463
         }
422 464
 
423 465
         // Check scope name
424 466
         $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
425
-        if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName()) {
467
+        if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName())
468
+        {
426 469
             throw new BadScopeException($scope, $class);
427 470
         }
428 471
 
429 472
         // We have to construct class using external injector when we know the exact context
430
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
473
+        if ($arguments === [] && $this->binder->hasInjector($class))
474
+        {
431 475
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
432 476
         }
433 477
 
434
-        if (!$reflection->isInstantiable()) {
478
+        if (!$reflection->isInstantiable())
479
+        {
435 480
             $itIs = match (true) {
436 481
                 $reflection->isEnum() => 'Enum',
437 482
                 $reflection->isAbstract() => 'Abstract class',
@@ -444,12 +489,16 @@  discard block
 block discarded – undo
444 489
 
445 490
         $constructor = $reflection->getConstructor();
446 491
 
447
-        if ($constructor !== null) {
448
-            try {
492
+        if ($constructor !== null)
493
+        {
494
+            try
495
+            {
449 496
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
450 497
                 $this->tracer->push(true);
451 498
                 $args = $this->resolver->resolveArguments($constructor, $arguments);
452
-            } catch (ValidationException $e) {
499
+            }
500
+            catch (ValidationException $e)
501
+            {
453 502
                 throw new ContainerException(
454 503
                     $this->tracer->combineTraceMessage(
455 504
                         \sprintf(
@@ -459,22 +508,31 @@  discard block
 block discarded – undo
459 508
                         )
460 509
                     ),
461 510
                 );
462
-            } finally {
511
+            }
512
+            finally
513
+            {
463 514
                 $this->tracer->pop(true);
464 515
                 $this->tracer->pop(false);
465 516
             }
466
-            try {
517
+            try
518
+            {
467 519
                 // Using constructor with resolved arguments
468 520
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
469 521
                 $this->tracer->push(true);
470 522
                 $instance = new $class(...$args);
471
-            } catch (\TypeError $e) {
523
+            }
524
+            catch (\TypeError $e)
525
+            {
472 526
                 throw new WrongTypeException($constructor, $e);
473
-            } finally {
527
+            }
528
+            finally
529
+            {
474 530
                 $this->tracer->pop(true);
475 531
                 $this->tracer->pop(false);
476 532
             }
477
-        } else {
533
+        }
534
+        else
535
+        {
478 536
             // No constructor specified
479 537
             $instance = $reflection->newInstance();
480 538
         }
@@ -492,13 +550,15 @@  discard block
 block discarded – undo
492 550
         $instance = $this->runInflector($instance);
493 551
 
494 552
         //Declarative singletons
495
-        if ($this->isSingleton($ctx)) {
553
+        if ($this->isSingleton($ctx))
554
+        {
496 555
             $this->state->singletons[$ctx->alias] = $instance;
497 556
         }
498 557
 
499 558
         // Register finalizer
500 559
         $finalizer = $this->getFinalizer($ctx, $instance);
501
-        if ($finalizer !== null) {
560
+        if ($finalizer !== null)
561
+        {
502 562
             $this->state->finalizers[] = $finalizer;
503 563
         }
504 564
 
@@ -510,12 +570,14 @@  discard block
 block discarded – undo
510 570
      */
511 571
     private function isSingleton(Ctx $ctx): bool
512 572
     {
513
-        if ($ctx->singleton === true) {
573
+        if ($ctx->singleton === true)
574
+        {
514 575
             return true;
515 576
         }
516 577
 
517 578
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
518
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
579
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class))
580
+        {
519 581
             return true;
520 582
         }
521 583
 
@@ -529,7 +591,8 @@  discard block
 block discarded – undo
529 591
          * @var Attribute\Finalize|null $attribute
530 592
          */
531 593
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
532
-        if ($attribute === null) {
594
+        if ($attribute === null)
595
+        {
533 596
             return null;
534 597
         }
535 598
 
@@ -543,10 +606,14 @@  discard block
 block discarded – undo
543 606
     {
544 607
         $scope = $this->scope;
545 608
 
546
-        while ($scope !== null) {
547
-            foreach ($this->state->inflectors as $class => $inflectors) {
548
-                if ($instance instanceof $class) {
549
-                    foreach ($inflectors as $inflector) {
609
+        while ($scope !== null)
610
+        {
611
+            foreach ($this->state->inflectors as $class => $inflectors)
612
+            {
613
+                if ($instance instanceof $class)
614
+                {
615
+                    foreach ($inflectors as $inflector)
616
+                    {
550 617
                         $instance = $inflector->getParametersCount() > 1
551 618
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
552 619
                             : ($inflector->inflector)($instance);
@@ -562,9 +629,12 @@  discard block
 block discarded – undo
562 629
 
563 630
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
564 631
     {
565
-        try {
632
+        try
633
+        {
566 634
             $this->resolver->validateArguments($reflection, $arguments);
567
-        } catch (\Throwable) {
635
+        }
636
+        catch (\Throwable)
637
+        {
568 638
             return false;
569 639
         }
570 640
 
Please login to merge, or discard this patch.
src/Core/src/Container.php 1 patch
Braces   +46 added lines, -21 removed lines patch added patch discarded remove patch
@@ -171,23 +171,29 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function runScope(Scope|array $bindings, callable $scope): mixed
173 173
     {
174
-        if (!\is_array($bindings)) {
174
+        if (!\is_array($bindings))
175
+        {
175 176
             return $this->runIsolatedScope($bindings, $scope);
176 177
         }
177 178
 
178 179
         $binds = &$this->state->bindings;
179 180
         $singletons = &$this->state->singletons;
180 181
         $cleanup = $previous = $prevSin = [];
181
-        foreach ($bindings as $alias => $resolver) {
182
+        foreach ($bindings as $alias => $resolver)
183
+        {
182 184
             // Store previous bindings
183
-            if (isset($binds[$alias])) {
185
+            if (isset($binds[$alias]))
186
+            {
184 187
                 $previous[$alias] = $binds[$alias];
185
-            } else {
188
+            }
189
+            else
190
+            {
186 191
                 // Store bindings to be removed
187 192
                 $cleanup[] = $alias;
188 193
             }
189 194
             // Store previous singletons
190
-            if (isset($singletons[$alias])) {
195
+            if (isset($singletons[$alias]))
196
+            {
191 197
                 $prevSin[$alias] = $singletons[$alias];
192 198
                 unset($singletons[$alias]);
193 199
             }
@@ -195,21 +201,27 @@  discard block
 block discarded – undo
195 201
             $this->binder->bind($alias, $resolver);
196 202
         }
197 203
 
198
-        try {
204
+        try
205
+        {
199 206
             return ContainerScope::getContainer() !== $this
200 207
                 ? ContainerScope::runScope($this, $scope)
201 208
                 : $scope($this);
202
-        } finally {
209
+        }
210
+        finally
211
+        {
203 212
             // Remove new bindings
204
-            foreach ($cleanup as $alias) {
213
+            foreach ($cleanup as $alias)
214
+            {
205 215
                 unset($binds[$alias], $singletons[$alias]);
206 216
             }
207 217
             // Restore previous bindings
208
-            foreach ($previous as $alias => $resolver) {
218
+            foreach ($previous as $alias => $resolver)
219
+            {
209 220
                 $binds[$alias] = $resolver;
210 221
             }
211 222
             // Restore singletons
212
-            foreach ($prevSin as $alias => $instance) {
223
+            foreach ($prevSin as $alias => $instance)
224
+            {
213 225
                 $singletons[$alias] = $instance;
214 226
             }
215 227
         }
@@ -257,7 +269,8 @@  discard block
 block discarded – undo
257 269
      */
258 270
     public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
259 271
     {
260
-        if ($force) {
272
+        if ($force)
273
+        {
261 274
             $this->binder->removeBinding($alias);
262 275
         }
263 276
 
@@ -328,8 +341,10 @@  discard block
 block discarded – undo
328 341
         ], $this->options);
329 342
 
330 343
         // Create container services
331
-        foreach ($container->config as $property => $class) {
332
-            if (\property_exists($container, $property)) {
344
+        foreach ($container->config as $property => $class)
345
+        {
346
+            if (\property_exists($container, $property))
347
+            {
333 348
                 $container->$property = $constructor->get($property, $class);
334 349
             }
335 350
         }
@@ -343,7 +358,8 @@  discard block
 block discarded – undo
343 358
     private function closeScope(): void
344 359
     {
345 360
         /** @psalm-suppress RedundantPropertyInitializationCheck */
346
-        if (!isset($this->scope)) {
361
+        if (!isset($this->scope))
362
+        {
347 363
             $this->destruct();
348 364
             return;
349 365
         }
@@ -352,10 +368,14 @@  discard block
 block discarded – undo
352 368
 
353 369
         // Run finalizers
354 370
         $errors = [];
355
-        foreach ($this->state->finalizers as $finalizer) {
356
-            try {
371
+        foreach ($this->state->finalizers as $finalizer)
372
+        {
373
+            try
374
+            {
357 375
                 $this->invoker->invoke($finalizer);
358
-            } catch (\Throwable $e) {
376
+            }
377
+            catch (\Throwable $e)
378
+            {
359 379
                 $errors[] = $e;
360 380
             }
361 381
         }
@@ -364,7 +384,8 @@  discard block
 block discarded – undo
364 384
         $this->destruct();
365 385
 
366 386
         // Throw collected errors
367
-        if ($errors !== []) {
387
+        if ($errors !== [])
388
+        {
368 389
             throw new FinalizersException($scopeName, $errors);
369 390
         }
370 391
     }
@@ -386,18 +407,22 @@  discard block
 block discarded – undo
386 407
         $container->scope->setParent($this, $this->scope, $this->factory);
387 408
 
388 409
         // Add specific bindings
389
-        foreach ($config->bindings as $alias => $resolver) {
410
+        foreach ($config->bindings as $alias => $resolver)
411
+        {
390 412
             $container->binder->bind($alias, $resolver);
391 413
         }
392 414
 
393 415
         return ContainerScope::runScope(
394 416
             $container,
395 417
             static function (self $container) use ($config, $closure): mixed {
396
-                try {
418
+                try
419
+                {
397 420
                     return $config->autowire
398 421
                         ? $container->invoke($closure)
399 422
                         : $closure($container);
400
-                } finally {
423
+                }
424
+                finally
425
+                {
401 426
                     $container->closeScope();
402 427
                 }
403 428
             }
Please login to merge, or discard this patch.