Passed
Push — master ( 37709b...f45e89 )
by Aleksei
06:22 queued 17s
created
src/Framework/Bootloader/Http/SessionBootloader.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 {
27 27
     public function __construct(
28 28
         private readonly BinderInterface $binder,
29
-    ) {
29
+    ){
30 30
     }
31 31
 
32 32
     public function defineBindings(): array
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 SessionInterface::class,
38 38
                 new Proxy(SessionInterface::class, false, $this->resolveSession(...)),
39 39
             );
40
-        $this->binder->bind(SessionInterface::class, new Proxy(SessionInterface::class, true), );
40
+        $this->binder->bind(SessionInterface::class, new Proxy(SessionInterface::class, true),);
41 41
 
42 42
         return [];
43 43
     }
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
                 'handler' => new Autowire(
72 72
                     FileHandler::class,
73 73
                     [
74
-                        'directory' => $directories->get('runtime') . 'session',
74
+                        'directory' => $directories->get('runtime').'session',
75 75
                         'lifetime' => 86400,
76 76
                     ]
77 77
                 ),
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 
91 91
     private function resolveSession(ContainerInterface $container): SessionInterface
92 92
     {
93
-        try {
93
+        try{
94 94
             /** @var ServerRequestInterface $request */
95 95
             $request = $container->get(ServerRequestInterface::class);
96 96
             return $request->getAttribute(SessionMiddleware::ATTRIBUTE) ?? throw new ContextualObjectNotFoundException(
97 97
                 SessionInterface::class,
98 98
                 SessionMiddleware::ATTRIBUTE,
99 99
             );
100
-        } catch (InvalidRequestScopeException $e) {
100
+        }catch (InvalidRequestScopeException $e){
101 101
             throw new InvalidRequestScopeException(SessionInterface::class, previous: $e);
102 102
         }
103 103
     }
Please login to merge, or discard this 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/Exception/InvalidRequestScopeException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@
 block discarded – undo
19 19
 {
20 20
     public function __construct(
21 21
         string $id,
22
-        string|Container|null $scopeOrContainer = null,
23
-        \Throwable|null $previous = null,
24
-    ) {
22
+        string | Container | null $scopeOrContainer = null,
23
+        \Throwable | null $previous = null,
24
+    ){
25 25
         parent::__construct($id, $scopeOrContainer, Spiral::HttpRequest->value, $previous);
26 26
     }
27 27
 }
Please login to merge, or discard this patch.
src/Framework/Bootloader/Http/CookiesBootloader.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     public function __construct(
23 23
         private readonly ConfiguratorInterface $config,
24 24
         private readonly BinderInterface $binder,
25
-    ) {
25
+    ){
26 26
     }
27 27
 
28 28
     public function defineBindings(): array
@@ -54,12 +54,12 @@  discard block
 block discarded – undo
54 54
 
55 55
     private function cookieQueue(ServerRequestInterface $request): CookieQueue
56 56
     {
57
-        try {
57
+        try{
58 58
             return $request->getAttribute(CookieQueue::ATTRIBUTE) ?? throw new ContextualObjectNotFoundException(
59 59
                 CookieQueue::class,
60 60
                 CookieQueue::ATTRIBUTE,
61 61
             );
62
-        } catch (InvalidRequestScopeException $e) {
62
+        }catch (InvalidRequestScopeException $e){
63 63
             throw new InvalidRequestScopeException(CookieQueue::class, previous: $e);
64 64
         }
65 65
     }
Please login to merge, or discard this 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/Exception/Shared/InvalidContainerScopeException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@
 block discarded – undo
16 16
     protected string $scope;
17 17
     public function __construct(
18 18
         protected readonly string $id,
19
-        Container|string|null $scopeOrContainer = null,
19
+        Container | string | null $scopeOrContainer = null,
20 20
         protected readonly ?string $requiredScope = null,
21
-        \Throwable|null $previous = null,
22
-    ) {
21
+        \Throwable | null $previous = null,
22
+    ){
23 23
         $this->scope = \is_string($scopeOrContainer)
24 24
             ? $scopeOrContainer
25 25
             : Introspector::scopeName($scopeOrContainer);
Please login to merge, or discard this patch.
src/Core/src/Exception/Container/RecursiveProxyException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@
 block discarded – undo
13 13
     public function __construct(
14 14
         public readonly string $alias,
15 15
         public readonly ?string $bindingScope = null,
16
-        public readonly ?array $callingScope = null,
17
-    ) {
16
+        public readonly ? array $callingScope = null,
17
+    ){
18 18
         $message = "Recursive proxy detected for `$alias`.";
19 19
         $bindingScope === null or $message .= "\nBinding scope: `$bindingScope`.";
20
-        $callingScope === null or $message .= "\nCalling scope: `" . \implode('.', $callingScope) . '`.';
20
+        $callingScope === null or $message .= "\nCalling scope: `".\implode('.', $callingScope).'`.';
21 21
         parent::__construct($message);
22 22
     }
23 23
 }
Please login to merge, or discard this patch.
src/Core/src/Config/Proxy.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@
 block discarded – undo
17 17
     public function __construct(
18 18
         protected readonly string $interface,
19 19
         public readonly bool $singleton = false,
20
-        public readonly ?\Closure $fallbackFactory = null,
21
-    ) {
20
+        public readonly ? \Closure $fallbackFactory = null,
21
+    ){
22 22
         \interface_exists($interface) or throw new \InvalidArgumentException(
23 23
             "Interface `{$interface}` does not exist.",
24 24
         );
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 2 patches
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @throws \Throwable
70 70
      */
71
-    public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed
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
             return $this->state->singletons[$alias];
75 75
         }
76 76
 
77 77
         $binding = $this->state->bindings[$alias] ?? null;
78 78
 
79
-        if ($binding === null) {
79
+        if ($binding === null){
80 80
             return $this->resolveWithoutBinding($alias, $parameters, $context);
81 81
         }
82 82
 
83
-        try {
83
+        try{
84 84
             $this->tracer->push(
85 85
                 false,
86 86
                 action: 'resolve from binding',
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                     ->resolveWeakReference($binding, $alias, $context, $parameters),
111 111
                 default => $binding,
112 112
             };
113
-        } finally {
113
+        }finally{
114 114
             $this->state->bindings[$alias] ??= $binding;
115 115
             $this->tracer->pop(true);
116 116
             $this->tracer->pop(false);
@@ -124,18 +124,18 @@  discard block
 block discarded – undo
124 124
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments)
125 125
     {
126 126
         $context = $ctx->context;
127
-        try {
127
+        try{
128 128
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
129
-        } catch (\ReflectionException $e) {
129
+        }catch (\ReflectionException $e){
130 130
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
131 131
         }
132 132
 
133 133
         $injector = $binding->injector;
134 134
 
135
-        try {
135
+        try{
136 136
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
137 137
 
138
-            if (!$injectorInstance instanceof InjectorInterface) {
138
+            if (!$injectorInstance instanceof InjectorInterface){
139 139
                 throw new InjectionException(
140 140
                     \sprintf(
141 141
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
                 default => (string)$context,
163 163
             });
164 164
 
165
-            if (!$reflection->isInstance($instance)) {
165
+            if (!$reflection->isInstance($instance)){
166 166
                 throw new InjectionException(
167 167
                     \sprintf(
168 168
                         "Invalid injection response for '%s'.",
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
             }
173 173
 
174 174
             return $instance;
175
-        } finally {
175
+        }finally{
176 176
             $this->state->bindings[$ctx->class] ??= $binding;
177 177
         }
178 178
     }
@@ -180,27 +180,27 @@  discard block
 block discarded – undo
180 180
     private function resolveAlias(
181 181
         Config\Alias $binding,
182 182
         string $alias,
183
-        Stringable|string|null $context,
183
+        Stringable | string | null $context,
184 184
         array $arguments,
185 185
     ): mixed {
186 186
         $result = $binding->alias === $alias
187 187
             ? $this->autowire(
188
-                new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton),
188
+                new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton),
189 189
                 $arguments,
190 190
             )
191 191
             //Binding is pointing to something else
192 192
             : $this->make($binding->alias, $arguments, $context);
193 193
 
194
-        if ($binding->singleton && $arguments === []) {
194
+        if ($binding->singleton && $arguments === []){
195 195
             $this->state->singletons[$alias] = $result;
196 196
         }
197 197
 
198 198
         return $result;
199 199
     }
200 200
 
201
-    private function resolveProxy(Config\Proxy $binding, string $alias, Stringable|string|null $context): mixed
201
+    private function resolveProxy(Config\Proxy $binding, string $alias, Stringable | string | null $context): mixed
202 202
     {
203
-        if ($context instanceof RetryContext) {
203
+        if ($context instanceof RetryContext){
204 204
             return $binding->fallbackFactory === null
205 205
                 ? throw new RecursiveProxyException(
206 206
                     $alias,
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 
212 212
         $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy());
213 213
 
214
-        if ($binding->singleton) {
214
+        if ($binding->singleton){
215 215
             $this->state->singletons[$alias] = $result;
216 216
         }
217 217
 
@@ -221,13 +221,13 @@  discard block
 block discarded – undo
221 221
     private function resolveShared(
222 222
         Config\Shared $binding,
223 223
         string $alias,
224
-        Stringable|string|null $context,
224
+        Stringable | string | null $context,
225 225
         array $arguments,
226 226
     ): object {
227 227
         $avoidCache = $arguments !== [];
228 228
         return $avoidCache
229 229
             ? $this->createInstance(
230
-                new Ctx(alias: $alias, class: $binding->value::class, context: $context),
230
+                new Ctx(alias : $alias, class : $binding->value::class, context : $context),
231 231
                 $arguments,
232 232
             )
233 233
             : $binding->value;
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     private function resolveAutowire(
237 237
         Config\Autowire $binding,
238 238
         string $alias,
239
-        Stringable|string|null $context,
239
+        Stringable | string | null $context,
240 240
         array $arguments,
241 241
     ): mixed {
242 242
         $instance = $binding->autowire->resolve($this, $arguments);
@@ -246,17 +246,17 @@  discard block
 block discarded – undo
246 246
     }
247 247
 
248 248
     private function resolveFactory(
249
-        Config\Factory|Config\DeferredFactory $binding,
249
+        Config\Factory | Config\DeferredFactory $binding,
250 250
         string $alias,
251
-        Stringable|string|null $context,
251
+        Stringable | string | null $context,
252 252
         array $arguments,
253 253
     ): mixed {
254 254
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
255
-        try {
255
+        try{
256 256
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
257 257
                 ? ($binding->factory)()
258 258
                 : $this->invoker->invoke($binding->factory, $arguments);
259
-        } catch (NotCallableException $e) {
259
+        }catch (NotCallableException $e){
260 260
             throw new ContainerException(
261 261
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
262 262
                 $e->getCode(),
@@ -270,24 +270,24 @@  discard block
 block discarded – undo
270 270
     private function resolveWeakReference(
271 271
         Config\WeakReference $binding,
272 272
         string $alias,
273
-        Stringable|string|null $context,
273
+        Stringable | string | null $context,
274 274
         array $arguments,
275 275
     ): ?object {
276 276
         $avoidCache = $arguments !== [];
277 277
 
278
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
279
-            try {
278
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){
279
+            try{
280 280
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
281 281
 
282 282
                 $object = $this->createInstance(
283 283
                     new Ctx(alias: $alias, class: $alias, context: $context),
284 284
                     $arguments,
285 285
                 );
286
-                if ($avoidCache) {
286
+                if ($avoidCache){
287 287
                     return $object;
288 288
                 }
289 289
                 $binding->reference = WeakReference::create($object);
290
-            } catch (\Throwable) {
290
+            }catch (\Throwable){
291 291
                 throw new ContainerException(
292 292
                     $this->tracer->combineTraceMessage(
293 293
                         \sprintf(
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                         )
298 298
                     )
299 299
                 );
300
-            } finally {
300
+            }finally{
301 301
                 $this->tracer->pop();
302 302
             }
303 303
         }
@@ -308,23 +308,23 @@  discard block
 block discarded – undo
308 308
     private function resolveWithoutBinding(
309 309
         string $alias,
310 310
         array $parameters = [],
311
-        Stringable|string|null $context = null
311
+        Stringable | string | null $context = null
312 312
     ): mixed {
313 313
         $parent = $this->scope->getParentFactory();
314 314
 
315
-        if ($parent !== null) {
316
-            try {
315
+        if ($parent !== null){
316
+            try{
317 317
                 $this->tracer->push(false, ...[
318 318
                     'current scope' => $this->scope->getScopeName(),
319 319
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
320 320
                 ]);
321 321
                 /** @psalm-suppress TooManyArguments */
322 322
                 return $parent->make($alias, $parameters, $context);
323
-            } catch (BadScopeException $e) {
324
-                if ($this->scope->getScopeName() !== $e->getScope()) {
323
+            }catch (BadScopeException $e){
324
+                if ($this->scope->getScopeName() !== $e->getScope()){
325 325
                     throw $e;
326 326
                 }
327
-            } catch (ContainerExceptionInterface $e) {
327
+            }catch (ContainerExceptionInterface $e){
328 328
                 $className = match (true) {
329 329
                     $e instanceof NotFoundException => NotFoundException::class,
330 330
                     $e instanceof RecursiveProxyException => throw $e,
@@ -334,19 +334,19 @@  discard block
 block discarded – undo
334 334
                     'Can\'t resolve `%s`.',
335 335
                     $alias,
336 336
                 )), previous: $e);
337
-            } finally {
337
+            }finally{
338 338
                 $this->tracer->pop(false);
339 339
             }
340 340
         }
341 341
 
342 342
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
343
-        try {
343
+        try{
344 344
             //No direct instructions how to construct class, make is automatically
345 345
             return $this->autowire(
346 346
                 new Ctx(alias: $alias, class: $alias, context: $context),
347 347
                 $parameters,
348 348
             );
349
-        } finally {
349
+        }finally{
350 350
             $this->tracer->pop(false);
351 351
         }
352 352
     }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                 &&
368 368
                 (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class))
369 369
         ))
370
-        ) {
370
+        ){
371 371
             throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf(
372 372
                 'Can\'t resolve `%s`: undefined class or binding `%s`.',
373 373
                 $this->tracer->getRootAlias(),
@@ -393,13 +393,13 @@  discard block
 block discarded – undo
393 393
         Ctx $ctx,
394 394
         array $arguments,
395 395
     ): object {
396
-        if ($this->options->checkScope) {
396
+        if ($this->options->checkScope){
397 397
             // Check scope name
398 398
             $ctx->reflection = new \ReflectionClass($instance);
399 399
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
400
-            if ($scopeName !== null) {
400
+            if ($scopeName !== null){
401 401
                 $scope = $this->scope;
402
-                while ($scope->getScopeName() !== $scopeName) {
402
+                while ($scope->getScopeName() !== $scopeName){
403 403
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
404 404
                 }
405 405
             }
@@ -428,26 +428,26 @@  discard block
 block discarded – undo
428 428
         array $arguments,
429 429
     ): object {
430 430
         $class = $ctx->class;
431
-        try {
431
+        try{
432 432
             $ctx->reflection = $reflection = new \ReflectionClass($class);
433
-        } catch (\ReflectionException $e) {
433
+        }catch (\ReflectionException $e){
434 434
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
435 435
         }
436 436
 
437 437
         // Check scope name
438
-        if ($this->options->checkScope) {
438
+        if ($this->options->checkScope){
439 439
             $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
440
-            if ($scope !== null && $scope !== $this->scope->getScopeName()) {
440
+            if ($scope !== null && $scope !== $this->scope->getScopeName()){
441 441
                 throw new BadScopeException($scope, $class);
442 442
             }
443 443
         }
444 444
 
445 445
         // We have to construct class using external injector when we know the exact context
446
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
446
+        if ($arguments === [] && $this->binder->hasInjector($class)){
447 447
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
448 448
         }
449 449
 
450
-        if (!$reflection->isInstantiable()) {
450
+        if (!$reflection->isInstantiable()){
451 451
             $itIs = match (true) {
452 452
                 $reflection->isEnum() => 'Enum',
453 453
                 $reflection->isAbstract() => 'Abstract class',
@@ -460,12 +460,12 @@  discard block
 block discarded – undo
460 460
 
461 461
         $constructor = $reflection->getConstructor();
462 462
 
463
-        if ($constructor !== null) {
464
-            try {
463
+        if ($constructor !== null){
464
+            try{
465 465
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
466 466
                 $this->tracer->push(true);
467 467
                 $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments);
468
-            } catch (ValidationException $e) {
468
+            }catch (ValidationException $e){
469 469
                 throw new ContainerException(
470 470
                     $this->tracer->combineTraceMessage(
471 471
                         \sprintf(
@@ -475,22 +475,22 @@  discard block
 block discarded – undo
475 475
                         )
476 476
                     ),
477 477
                 );
478
-            } finally {
478
+            }finally{
479 479
                 $this->tracer->pop(true);
480 480
                 $this->tracer->pop(false);
481 481
             }
482
-            try {
482
+            try{
483 483
                 // Using constructor with resolved arguments
484 484
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
485 485
                 $this->tracer->push(true);
486 486
                 $instance = new $class(...$args);
487
-            } catch (\TypeError $e) {
487
+            }catch (\TypeError $e){
488 488
                 throw new WrongTypeException($constructor, $e);
489
-            } finally {
489
+            }finally{
490 490
                 $this->tracer->pop(true);
491 491
                 $this->tracer->pop(false);
492 492
             }
493
-        } else {
493
+        }else{
494 494
             // No constructor specified
495 495
             $instance = $reflection->newInstance();
496 496
         }
@@ -508,13 +508,13 @@  discard block
 block discarded – undo
508 508
         $instance = $this->runInflector($instance);
509 509
 
510 510
         //Declarative singletons
511
-        if ($this->isSingleton($ctx)) {
511
+        if ($this->isSingleton($ctx)){
512 512
             $this->state->singletons[$ctx->alias] = $instance;
513 513
         }
514 514
 
515 515
         // Register finalizer
516 516
         $finalizer = $this->getFinalizer($ctx, $instance);
517
-        if ($finalizer !== null) {
517
+        if ($finalizer !== null){
518 518
             $this->state->finalizers[] = $finalizer;
519 519
         }
520 520
 
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
      */
527 527
     private function isSingleton(Ctx $ctx): bool
528 528
     {
529
-        if ($ctx->singleton === true) {
529
+        if ($ctx->singleton === true){
530 530
             return true;
531 531
         }
532 532
 
533 533
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
534
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
534
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class)){
535 535
             return true;
536 536
         }
537 537
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
          * @var Attribute\Finalize|null $attribute
546 546
          */
547 547
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
548
-        if ($attribute === null) {
548
+        if ($attribute === null){
549 549
             return null;
550 550
         }
551 551
 
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
     {
560 560
         $scope = $this->scope;
561 561
 
562
-        while ($scope !== null) {
563
-            foreach ($this->state->inflectors as $class => $inflectors) {
564
-                if ($instance instanceof $class) {
565
-                    foreach ($inflectors as $inflector) {
562
+        while ($scope !== null){
563
+            foreach ($this->state->inflectors as $class => $inflectors){
564
+                if ($instance instanceof $class){
565
+                    foreach ($inflectors as $inflector){
566 566
                         $instance = $inflector->getParametersCount() > 1
567 567
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
568 568
                             : ($inflector->inflector)($instance);
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
 
579 579
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
580 580
     {
581
-        try {
581
+        try{
582 582
             $this->resolver->validateArguments($reflection, $arguments);
583
-        } catch (\Throwable) {
583
+        }catch (\Throwable){
584 584
             return false;
585 585
         }
586 586
 
Please login to merge, or discard this 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 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -19,27 +19,27 @@  discard block
 block discarded – undo
19 19
 {
20 20
     public static function resolve(
21 21
         string $alias,
22
-        \Stringable|string|null $context = null,
22
+        \Stringable | string | null $context = null,
23 23
         ?ContainerInterface $c = null,
24 24
     ): object {
25 25
         $c ??= ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.');
26 26
 
27
-        try {
27
+        try{
28 28
             /** @psalm-suppress TooManyArguments */
29 29
             $result = $c->get($alias, $context) ?? throw new ContainerException(
30 30
                 'Resolved `null` from the container.',
31 31
             );
32
-        } catch (\Throwable $e) {
32
+        }catch (\Throwable $e){
33 33
             $scope = self::getScope($c);
34 34
             throw new ContainerException(
35 35
                 $scope === null
36 36
                     ? "Unable to resolve `{$alias}` in a Proxy."
37 37
                     : \sprintf('Unable to resolve `%s` in a Proxy in `%s` scope.', $alias, \implode('.', $scope)),
38
-                previous: $e,
38
+                previous : $e,
39 39
             );
40 40
         }
41 41
 
42
-        if (!Proxy::isProxy($result)) {
42
+        if (!Proxy::isProxy($result)){
43 43
             return $result;
44 44
         }
45 45
 
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
          * to try to get the instance from the Proxy Fallback Factory.
49 49
          * If there is no the Proxy Fallback Factory, {@see RecursiveProxyException} will be thrown.
50 50
          */
51
-        try {
51
+        try{
52 52
             /** @psalm-suppress TooManyArguments */
53 53
             $result = $c->get($alias, new RetryContext($context));
54
-        } catch (RecursiveProxyException $e) {
54
+        }catch (RecursiveProxyException $e){
55 55
             throw new RecursiveProxyException($e->alias, $e->bindingScope, self::getScope($c));
56 56
         }
57 57
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      */
67 67
     private static function getScope(ContainerInterface $c): ?array
68 68
     {
69
-        if (!$c instanceof Container) {
70
-            if (!Proxy::isProxy($c)) {
69
+        if (!$c instanceof Container){
70
+            if (!Proxy::isProxy($c)){
71 71
                 return null;
72 72
             }
73 73
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         }
76 76
 
77 77
         return \array_reverse(\array_map(
78
-            static fn (?string $name): string => $name ?? 'null',
78
+            static fn (?string $name) : string => $name ?? 'null',
79 79
             Introspector::scopeNames($c),
80 80
         ));
81 81
     }
Please login to merge, or discard this 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.
src/Core/src/Internal/Proxy/RetryContext.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
      * @param \Stringable|string|null $context Original context.
16 16
      */
17 17
     public function __construct(
18
-        public \Stringable|string|null $context = null,
19
-    ) {
18
+        public \Stringable | string | null $context = null,
19
+    ){
20 20
     }
21 21
 
22 22
     public function __toString(): string
23 23
     {
24
-        return (string) $this->context;
24
+        return (string)$this->context;
25 25
     }
26 26
 }
Please login to merge, or discard this patch.