Passed
Push — master ( 37709b...f45e89 )
by Aleksei
06:22 queued 17s
created
src/Framework/Bootloader/Http/SessionBootloader.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,14 +90,17 @@
 block discarded – undo
90 90
 
91 91
     private function resolveSession(ContainerInterface $container): SessionInterface
92 92
     {
93
-        try {
93
+        try
94
+        {
94 95
             /** @var ServerRequestInterface $request */
95 96
             $request = $container->get(ServerRequestInterface::class);
96 97
             return $request->getAttribute(SessionMiddleware::ATTRIBUTE) ?? throw new ContextualObjectNotFoundException(
97 98
                 SessionInterface::class,
98 99
                 SessionMiddleware::ATTRIBUTE,
99 100
             );
100
-        } catch (InvalidRequestScopeException $e) {
101
+        }
102
+        catch (InvalidRequestScopeException $e)
103
+        {
101 104
             throw new InvalidRequestScopeException(SessionInterface::class, previous: $e);
102 105
         }
103 106
     }
Please login to merge, or discard this patch.
src/Framework/Bootloader/Http/CookiesBootloader.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,12 +54,15 @@
 block discarded – undo
54 54
 
55 55
     private function cookieQueue(ServerRequestInterface $request): CookieQueue
56 56
     {
57
-        try {
57
+        try
58
+        {
58 59
             return $request->getAttribute(CookieQueue::ATTRIBUTE) ?? throw new ContextualObjectNotFoundException(
59 60
                 CookieQueue::class,
60 61
                 CookieQueue::ATTRIBUTE,
61 62
             );
62
-        } catch (InvalidRequestScopeException $e) {
63
+        }
64
+        catch (InvalidRequestScopeException $e)
65
+        {
63 66
             throw new InvalidRequestScopeException(CookieQueue::class, previous: $e);
64 67
         }
65 68
     }
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 1 patch
Braces   +129 added lines, -56 removed lines patch added patch discarded remove patch
@@ -70,17 +70,20 @@  discard block
 block discarded – undo
70 70
      */
71 71
     public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed
72 72
     {
73
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
73
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons))
74
+        {
74 75
             return $this->state->singletons[$alias];
75 76
         }
76 77
 
77 78
         $binding = $this->state->bindings[$alias] ?? null;
78 79
 
79
-        if ($binding === null) {
80
+        if ($binding === null)
81
+        {
80 82
             return $this->resolveWithoutBinding($alias, $parameters, $context);
81 83
         }
82 84
 
83
-        try {
85
+        try
86
+        {
84 87
             $this->tracer->push(
85 88
                 false,
86 89
                 action: 'resolve from binding',
@@ -110,7 +113,9 @@  discard block
 block discarded – undo
110 113
                     ->resolveWeakReference($binding, $alias, $context, $parameters),
111 114
                 default => $binding,
112 115
             };
113
-        } finally {
116
+        }
117
+        finally
118
+        {
114 119
             $this->state->bindings[$alias] ??= $binding;
115 120
             $this->tracer->pop(true);
116 121
             $this->tracer->pop(false);
@@ -124,18 +129,23 @@  discard block
 block discarded – undo
124 129
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments)
125 130
     {
126 131
         $context = $ctx->context;
127
-        try {
132
+        try
133
+        {
128 134
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
129
-        } catch (\ReflectionException $e) {
135
+        }
136
+        catch (\ReflectionException $e)
137
+        {
130 138
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
131 139
         }
132 140
 
133 141
         $injector = $binding->injector;
134 142
 
135
-        try {
143
+        try
144
+        {
136 145
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
137 146
 
138
-            if (!$injectorInstance instanceof InjectorInterface) {
147
+            if (!$injectorInstance instanceof InjectorInterface)
148
+            {
139 149
                 throw new InjectionException(
140 150
                     \sprintf(
141 151
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -162,7 +172,8 @@  discard block
 block discarded – undo
162 172
                 default => (string)$context,
163 173
             });
164 174
 
165
-            if (!$reflection->isInstance($instance)) {
175
+            if (!$reflection->isInstance($instance))
176
+            {
166 177
                 throw new InjectionException(
167 178
                     \sprintf(
168 179
                         "Invalid injection response for '%s'.",
@@ -172,7 +183,9 @@  discard block
 block discarded – undo
172 183
             }
173 184
 
174 185
             return $instance;
175
-        } finally {
186
+        }
187
+        finally
188
+        {
176 189
             $this->state->bindings[$ctx->class] ??= $binding;
177 190
         }
178 191
     }
@@ -191,7 +204,8 @@  discard block
 block discarded – undo
191 204
             //Binding is pointing to something else
192 205
             : $this->make($binding->alias, $arguments, $context);
193 206
 
194
-        if ($binding->singleton && $arguments === []) {
207
+        if ($binding->singleton && $arguments === [])
208
+        {
195 209
             $this->state->singletons[$alias] = $result;
196 210
         }
197 211
 
@@ -200,7 +214,8 @@  discard block
 block discarded – undo
200 214
 
201 215
     private function resolveProxy(Config\Proxy $binding, string $alias, Stringable|string|null $context): mixed
202 216
     {
203
-        if ($context instanceof RetryContext) {
217
+        if ($context instanceof RetryContext)
218
+        {
204 219
             return $binding->fallbackFactory === null
205 220
                 ? throw new RecursiveProxyException(
206 221
                     $alias,
@@ -211,7 +226,8 @@  discard block
 block discarded – undo
211 226
 
212 227
         $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy());
213 228
 
214
-        if ($binding->singleton) {
229
+        if ($binding->singleton)
230
+        {
215 231
             $this->state->singletons[$alias] = $result;
216 232
         }
217 233
 
@@ -252,11 +268,14 @@  discard block
 block discarded – undo
252 268
         array $arguments,
253 269
     ): mixed {
254 270
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
255
-        try {
271
+        try
272
+        {
256 273
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
257 274
                 ? ($binding->factory)()
258 275
                 : $this->invoker->invoke($binding->factory, $arguments);
259
-        } catch (NotCallableException $e) {
276
+        }
277
+        catch (NotCallableException $e)
278
+        {
260 279
             throw new ContainerException(
261 280
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
262 281
                 $e->getCode(),
@@ -275,19 +294,24 @@  discard block
 block discarded – undo
275 294
     ): ?object {
276 295
         $avoidCache = $arguments !== [];
277 296
 
278
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
279
-            try {
297
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias))
298
+        {
299
+            try
300
+            {
280 301
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
281 302
 
282 303
                 $object = $this->createInstance(
283 304
                     new Ctx(alias: $alias, class: $alias, context: $context),
284 305
                     $arguments,
285 306
                 );
286
-                if ($avoidCache) {
307
+                if ($avoidCache)
308
+                {
287 309
                     return $object;
288 310
                 }
289 311
                 $binding->reference = WeakReference::create($object);
290
-            } catch (\Throwable) {
312
+            }
313
+            catch (\Throwable)
314
+            {
291 315
                 throw new ContainerException(
292 316
                     $this->tracer->combineTraceMessage(
293 317
                         \sprintf(
@@ -297,7 +321,9 @@  discard block
 block discarded – undo
297 321
                         )
298 322
                     )
299 323
                 );
300
-            } finally {
324
+            }
325
+            finally
326
+            {
301 327
                 $this->tracer->pop();
302 328
             }
303 329
         }
@@ -312,19 +338,26 @@  discard block
 block discarded – undo
312 338
     ): mixed {
313 339
         $parent = $this->scope->getParentFactory();
314 340
 
315
-        if ($parent !== null) {
316
-            try {
341
+        if ($parent !== null)
342
+        {
343
+            try
344
+            {
317 345
                 $this->tracer->push(false, ...[
318 346
                     'current scope' => $this->scope->getScopeName(),
319 347
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
320 348
                 ]);
321 349
                 /** @psalm-suppress TooManyArguments */
322 350
                 return $parent->make($alias, $parameters, $context);
323
-            } catch (BadScopeException $e) {
324
-                if ($this->scope->getScopeName() !== $e->getScope()) {
351
+            }
352
+            catch (BadScopeException $e)
353
+            {
354
+                if ($this->scope->getScopeName() !== $e->getScope())
355
+                {
325 356
                     throw $e;
326 357
                 }
327
-            } catch (ContainerExceptionInterface $e) {
358
+            }
359
+            catch (ContainerExceptionInterface $e)
360
+            {
328 361
                 $className = match (true) {
329 362
                     $e instanceof NotFoundException => NotFoundException::class,
330 363
                     $e instanceof RecursiveProxyException => throw $e,
@@ -334,19 +367,24 @@  discard block
 block discarded – undo
334 367
                     'Can\'t resolve `%s`.',
335 368
                     $alias,
336 369
                 )), previous: $e);
337
-            } finally {
370
+            }
371
+            finally
372
+            {
338 373
                 $this->tracer->pop(false);
339 374
             }
340 375
         }
341 376
 
342 377
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
343
-        try {
378
+        try
379
+        {
344 380
             //No direct instructions how to construct class, make is automatically
345 381
             return $this->autowire(
346 382
                 new Ctx(alias: $alias, class: $alias, context: $context),
347 383
                 $parameters,
348 384
             );
349
-        } finally {
385
+        }
386
+        finally
387
+        {
350 388
             $this->tracer->pop(false);
351 389
         }
352 390
     }
@@ -393,13 +431,16 @@  discard block
 block discarded – undo
393 431
         Ctx $ctx,
394 432
         array $arguments,
395 433
     ): object {
396
-        if ($this->options->checkScope) {
434
+        if ($this->options->checkScope)
435
+        {
397 436
             // Check scope name
398 437
             $ctx->reflection = new \ReflectionClass($instance);
399 438
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
400
-            if ($scopeName !== null) {
439
+            if ($scopeName !== null)
440
+            {
401 441
                 $scope = $this->scope;
402
-                while ($scope->getScopeName() !== $scopeName) {
442
+                while ($scope->getScopeName() !== $scopeName)
443
+                {
403 444
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
404 445
                 }
405 446
             }
@@ -428,26 +469,33 @@  discard block
 block discarded – undo
428 469
         array $arguments,
429 470
     ): object {
430 471
         $class = $ctx->class;
431
-        try {
472
+        try
473
+        {
432 474
             $ctx->reflection = $reflection = new \ReflectionClass($class);
433
-        } catch (\ReflectionException $e) {
475
+        }
476
+        catch (\ReflectionException $e)
477
+        {
434 478
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
435 479
         }
436 480
 
437 481
         // Check scope name
438
-        if ($this->options->checkScope) {
482
+        if ($this->options->checkScope)
483
+        {
439 484
             $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
440
-            if ($scope !== null && $scope !== $this->scope->getScopeName()) {
485
+            if ($scope !== null && $scope !== $this->scope->getScopeName())
486
+            {
441 487
                 throw new BadScopeException($scope, $class);
442 488
             }
443 489
         }
444 490
 
445 491
         // We have to construct class using external injector when we know the exact context
446
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
492
+        if ($arguments === [] && $this->binder->hasInjector($class))
493
+        {
447 494
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
448 495
         }
449 496
 
450
-        if (!$reflection->isInstantiable()) {
497
+        if (!$reflection->isInstantiable())
498
+        {
451 499
             $itIs = match (true) {
452 500
                 $reflection->isEnum() => 'Enum',
453 501
                 $reflection->isAbstract() => 'Abstract class',
@@ -460,12 +508,16 @@  discard block
 block discarded – undo
460 508
 
461 509
         $constructor = $reflection->getConstructor();
462 510
 
463
-        if ($constructor !== null) {
464
-            try {
511
+        if ($constructor !== null)
512
+        {
513
+            try
514
+            {
465 515
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
466 516
                 $this->tracer->push(true);
467 517
                 $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments);
468
-            } catch (ValidationException $e) {
518
+            }
519
+            catch (ValidationException $e)
520
+            {
469 521
                 throw new ContainerException(
470 522
                     $this->tracer->combineTraceMessage(
471 523
                         \sprintf(
@@ -475,22 +527,31 @@  discard block
 block discarded – undo
475 527
                         )
476 528
                     ),
477 529
                 );
478
-            } finally {
530
+            }
531
+            finally
532
+            {
479 533
                 $this->tracer->pop(true);
480 534
                 $this->tracer->pop(false);
481 535
             }
482
-            try {
536
+            try
537
+            {
483 538
                 // Using constructor with resolved arguments
484 539
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
485 540
                 $this->tracer->push(true);
486 541
                 $instance = new $class(...$args);
487
-            } catch (\TypeError $e) {
542
+            }
543
+            catch (\TypeError $e)
544
+            {
488 545
                 throw new WrongTypeException($constructor, $e);
489
-            } finally {
546
+            }
547
+            finally
548
+            {
490 549
                 $this->tracer->pop(true);
491 550
                 $this->tracer->pop(false);
492 551
             }
493
-        } else {
552
+        }
553
+        else
554
+        {
494 555
             // No constructor specified
495 556
             $instance = $reflection->newInstance();
496 557
         }
@@ -508,13 +569,15 @@  discard block
 block discarded – undo
508 569
         $instance = $this->runInflector($instance);
509 570
 
510 571
         //Declarative singletons
511
-        if ($this->isSingleton($ctx)) {
572
+        if ($this->isSingleton($ctx))
573
+        {
512 574
             $this->state->singletons[$ctx->alias] = $instance;
513 575
         }
514 576
 
515 577
         // Register finalizer
516 578
         $finalizer = $this->getFinalizer($ctx, $instance);
517
-        if ($finalizer !== null) {
579
+        if ($finalizer !== null)
580
+        {
518 581
             $this->state->finalizers[] = $finalizer;
519 582
         }
520 583
 
@@ -526,12 +589,14 @@  discard block
 block discarded – undo
526 589
      */
527 590
     private function isSingleton(Ctx $ctx): bool
528 591
     {
529
-        if ($ctx->singleton === true) {
592
+        if ($ctx->singleton === true)
593
+        {
530 594
             return true;
531 595
         }
532 596
 
533 597
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
534
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
598
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class))
599
+        {
535 600
             return true;
536 601
         }
537 602
 
@@ -545,7 +610,8 @@  discard block
 block discarded – undo
545 610
          * @var Attribute\Finalize|null $attribute
546 611
          */
547 612
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
548
-        if ($attribute === null) {
613
+        if ($attribute === null)
614
+        {
549 615
             return null;
550 616
         }
551 617
 
@@ -559,10 +625,14 @@  discard block
 block discarded – undo
559 625
     {
560 626
         $scope = $this->scope;
561 627
 
562
-        while ($scope !== null) {
563
-            foreach ($this->state->inflectors as $class => $inflectors) {
564
-                if ($instance instanceof $class) {
565
-                    foreach ($inflectors as $inflector) {
628
+        while ($scope !== null)
629
+        {
630
+            foreach ($this->state->inflectors as $class => $inflectors)
631
+            {
632
+                if ($instance instanceof $class)
633
+                {
634
+                    foreach ($inflectors as $inflector)
635
+                    {
566 636
                         $instance = $inflector->getParametersCount() > 1
567 637
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
568 638
                             : ($inflector->inflector)($instance);
@@ -578,9 +648,12 @@  discard block
 block discarded – undo
578 648
 
579 649
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
580 650
     {
581
-        try {
651
+        try
652
+        {
582 653
             $this->resolver->validateArguments($reflection, $arguments);
583
-        } catch (\Throwable) {
654
+        }
655
+        catch (\Throwable)
656
+        {
584 657
             return false;
585 658
         }
586 659
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Proxy/Resolver.php 1 patch
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -24,12 +24,15 @@  discard block
 block discarded – undo
24 24
     ): object {
25 25
         $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.');
26 26
 
27
-        try {
27
+        try
28
+        {
28 29
             /** @psalm-suppress TooManyArguments */
29 30
             $result = $c->get($alias, $context) ?? throw new ContainerException(
30 31
                 'Resolved `null` from the container.',
31 32
             );
32
-        } catch (\Throwable $e) {
33
+        }
34
+        catch (\Throwable $e)
35
+        {
33 36
             $scope = self::getScope($c);
34 37
             throw new ContainerException(
35 38
                 $scope === null
@@ -39,7 +42,8 @@  discard block
 block discarded – undo
39 42
             );
40 43
         }
41 44
 
42
-        if (!Proxy::isProxy($result)) {
45
+        if (!Proxy::isProxy($result))
46
+        {
43 47
             return $result;
44 48
         }
45 49
 
@@ -48,10 +52,13 @@  discard block
 block discarded – undo
48 52
          * to try to get the instance from the Proxy Fallback Factory.
49 53
          * If there is no the Proxy Fallback Factory, {@see RecursiveProxyException} will be thrown.
50 54
          */
51
-        try {
55
+        try
56
+        {
52 57
             /** @psalm-suppress TooManyArguments */
53 58
             $result = $c->get($alias, new RetryContext($context));
54
-        } catch (RecursiveProxyException $e) {
59
+        }
60
+        catch (RecursiveProxyException $e)
61
+        {
55 62
             throw new RecursiveProxyException($e->alias, $e->bindingScope, self::getScope($c));
56 63
         }
57 64
 
@@ -66,8 +73,10 @@  discard block
 block discarded – undo
66 73
      */
67 74
     private static function getScope(ContainerInterface $c): ?array
68 75
     {
69
-        if (!$c instanceof Container) {
70
-            if (!Proxy::isProxy($c)) {
76
+        if (!$c instanceof Container)
77
+        {
78
+            if (!Proxy::isProxy($c))
79
+            {
71 80
                 return null;
72 81
             }
73 82
 
Please login to merge, or discard this patch.