Passed
Pull Request — master (#1077)
by Maxim
12:35
created
src/Core/tests/Internal/Proxy/ProxyTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
         self::expectExceptionMessageMatches('/Call to undefined method/i');
54 54
 
55
-        $root->invoke(static function (#[Proxy] EmptyInterface $proxy) {
55
+        $root->invoke(static function (#[Proxy] EmptyInterface $proxy){
56 56
             $proxy->bar(name: 'foo'); // Possible to run
57 57
         });
58 58
     }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
             $proxy = $$var;
93 93
             self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69));
94 94
             self::assertSame(
95
-                ['foo' => 'foo','zap' => 'bar', 'gas' => 69],
95
+                ['foo' => 'foo', 'zap' => 'bar', 'gas' => 69],
96 96
                 $proxy->extraVariadic(foo: 'foo', zap: 'bar', gas: 69),
97 97
             );
98 98
         });
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class);
178 178
         $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class);
179 179
 
180
-        $mock = $root->invoke(static fn(#[Proxy] MockInterface|EmptyInterface $mock) => $mock);
180
+        $mock = $root->invoke(static fn(#[Proxy] MockInterface | EmptyInterface $mock) => $mock);
181 181
 
182 182
         self::assertInstanceOf(MockInterfaceImpl::class, $mock);
183 183
     }
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     {
231 231
         \set_error_handler(static function (int $errno, string $error) use ($interface): void {
232 232
             self::assertSame(
233
-                \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be ' .
233
+                \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be '.
234 234
                     'impossible in version 4.0.', $interface),
235 235
                 $error
236 236
             );
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     public function testDeprecationProxyConfigDontThrowIfNotConstructed(string $interface): void
287 287
     {
288 288
         \set_error_handler(static function (int $errno, string $error) use ($interface): void {
289
-            self::fail('Unexpected error: ' . $error);
289
+            self::fail('Unexpected error: '.$error);
290 290
         });
291 291
 
292 292
         $root = new Container();
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
     }
307 307
 
308 308
     #[DataProvider('invalidDeprecationProxyArgsDataProvider')]
309
-    public function testDeprecationProxyConfigArgsRequiredException(string|null $scope, string|null $version): void
309
+    public function testDeprecationProxyConfigArgsRequiredException(string | null $scope, string | null $version): void
310 310
     {
311 311
         self::expectException(\InvalidArgumentException::class);
312 312
         self::expectExceptionMessage('Scope and version or custom message must be provided.');
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -63,19 +63,19 @@  discard block
 block discarded – undo
63 63
      *
64 64
      * @throws \Throwable
65 65
      */
66
-    public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed
66
+    public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed
67 67
     {
68
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
68
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){
69 69
             return $this->state->singletons[$alias];
70 70
         }
71 71
 
72 72
         $binding = $this->state->bindings[$alias] ?? null;
73 73
 
74
-        if ($binding === null) {
74
+        if ($binding === null){
75 75
             return $this->resolveWithoutBinding($alias, $parameters, $context);
76 76
         }
77 77
 
78
-        try {
78
+        try{
79 79
             $this->tracer->push(
80 80
                 false,
81 81
                 action: 'resolve from binding',
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                     ->resolveWeakReference($binding, $alias, $context, $parameters),
106 106
                 default => $binding,
107 107
             };
108
-        } finally {
108
+        }finally{
109 109
             $this->state->bindings[$alias] ??= $binding;
110 110
             $this->tracer->pop(true);
111 111
             $this->tracer->pop(false);
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments)
120 120
     {
121 121
         $context = $ctx->context;
122
-        try {
122
+        try{
123 123
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
124
-        } catch (\ReflectionException $e) {
124
+        }catch (\ReflectionException $e){
125 125
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
126 126
         }
127 127
 
128 128
         $injector = $binding->injector;
129 129
 
130
-        try {
130
+        try{
131 131
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
132 132
 
133
-            if (!$injectorInstance instanceof InjectorInterface) {
133
+            if (!$injectorInstance instanceof InjectorInterface){
134 134
                 throw new InjectionException(
135 135
                     \sprintf(
136 136
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                 default => (string)$context,
158 158
             });
159 159
 
160
-            if (!$reflection->isInstance($instance)) {
160
+            if (!$reflection->isInstance($instance)){
161 161
                 throw new InjectionException(
162 162
                     \sprintf(
163 163
                         "Invalid injection response for '%s'.",
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
             }
168 168
 
169 169
             return $instance;
170
-        } finally {
170
+        }finally{
171 171
             $this->state->bindings[$ctx->class] ??= $binding;
172 172
         }
173 173
     }
@@ -175,18 +175,18 @@  discard block
 block discarded – undo
175 175
     private function resolveAlias(
176 176
         Config\Alias $binding,
177 177
         string $alias,
178
-        Stringable|string|null $context,
178
+        Stringable | string | null $context,
179 179
         array $arguments,
180 180
     ): mixed {
181 181
         $result = $binding->alias === $alias
182 182
             ? $this->autowire(
183
-                new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton),
183
+                new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton),
184 184
                 $arguments,
185 185
             )
186 186
             //Binding is pointing to something else
187 187
             : $this->make($binding->alias, $arguments, $context);
188 188
 
189
-        if ($binding->singleton && $arguments === []) {
189
+        if ($binding->singleton && $arguments === []){
190 190
             $this->state->singletons[$alias] = $result;
191 191
         }
192 192
 
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
     private function resolveProxy(
197 197
         Config\Proxy $binding,
198 198
         string $alias,
199
-        Stringable|string|null $context,
199
+        Stringable | string | null $context,
200 200
         array $arguments,
201 201
     ): mixed {
202 202
         $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy());
203 203
 
204
-        if ($binding->singleton && $arguments === []) {
204
+        if ($binding->singleton && $arguments === []){
205 205
             $this->state->singletons[$alias] = $result;
206 206
         }
207 207
 
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
     private function resolveShared(
212 212
         Config\Shared $binding,
213 213
         string $alias,
214
-        Stringable|string|null $context,
214
+        Stringable | string | null $context,
215 215
         array $arguments,
216 216
     ): object {
217 217
         $avoidCache = $arguments !== [];
218 218
         return $avoidCache
219 219
             ? $this->createInstance(
220
-                new Ctx(alias: $alias, class: $binding->value::class, context: $context),
220
+                new Ctx(alias : $alias, class : $binding->value::class, context : $context),
221 221
                 $arguments,
222 222
             )
223 223
             : $binding->value;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
     private function resolveAutowire(
227 227
         Config\Autowire $binding,
228 228
         string $alias,
229
-        Stringable|string|null $context,
229
+        Stringable | string | null $context,
230 230
         array $arguments,
231 231
     ): mixed {
232 232
         $instance = $binding->autowire->resolve($this, $arguments);
@@ -236,17 +236,17 @@  discard block
 block discarded – undo
236 236
     }
237 237
 
238 238
     private function resolveFactory(
239
-        Config\Factory|Config\DeferredFactory $binding,
239
+        Config\Factory | Config\DeferredFactory $binding,
240 240
         string $alias,
241
-        Stringable|string|null $context,
241
+        Stringable | string | null $context,
242 242
         array $arguments,
243 243
     ): mixed {
244 244
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
245
-        try {
245
+        try{
246 246
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
247 247
                 ? ($binding->factory)()
248 248
                 : $this->invoker->invoke($binding->factory, $arguments);
249
-        } catch (NotCallableException $e) {
249
+        }catch (NotCallableException $e){
250 250
             throw new ContainerException(
251 251
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
252 252
                 $e->getCode(),
@@ -260,24 +260,24 @@  discard block
 block discarded – undo
260 260
     private function resolveWeakReference(
261 261
         Config\WeakReference $binding,
262 262
         string $alias,
263
-        Stringable|string|null $context,
263
+        Stringable | string | null $context,
264 264
         array $arguments,
265 265
     ): ?object {
266 266
         $avoidCache = $arguments !== [];
267 267
 
268
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
269
-            try {
268
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){
269
+            try{
270 270
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
271 271
 
272 272
                 $object = $this->createInstance(
273 273
                     new Ctx(alias: $alias, class: $alias, context: $context),
274 274
                     $arguments,
275 275
                 );
276
-                if ($avoidCache) {
276
+                if ($avoidCache){
277 277
                     return $object;
278 278
                 }
279 279
                 $binding->reference = WeakReference::create($object);
280
-            } catch (\Throwable) {
280
+            }catch (\Throwable){
281 281
                 throw new ContainerException(
282 282
                     $this->tracer->combineTraceMessage(
283 283
                         \sprintf(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
                         )
288 288
                     )
289 289
                 );
290
-            } finally {
290
+            }finally{
291 291
                 $this->tracer->pop();
292 292
             }
293 293
         }
@@ -298,23 +298,23 @@  discard block
 block discarded – undo
298 298
     private function resolveWithoutBinding(
299 299
         string $alias,
300 300
         array $parameters = [],
301
-        Stringable|string|null $context = null
301
+        Stringable | string | null $context = null
302 302
     ): mixed {
303 303
         $parent = $this->scope->getParentFactory();
304 304
 
305
-        if ($parent !== null) {
306
-            try {
305
+        if ($parent !== null){
306
+            try{
307 307
                 $this->tracer->push(false, ...[
308 308
                     'current scope' => $this->scope->getScopeName(),
309 309
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
310 310
                 ]);
311 311
                 /** @psalm-suppress TooManyArguments */
312 312
                 return $parent->make($alias, $parameters, $context);
313
-            } catch (BadScopeException $e) {
314
-                if ($this->scope->getScopeName() !== $e->getScope()) {
313
+            }catch (BadScopeException $e){
314
+                if ($this->scope->getScopeName() !== $e->getScope()){
315 315
                     throw $e;
316 316
                 }
317
-            } catch (ContainerExceptionInterface $e) {
317
+            }catch (ContainerExceptionInterface $e){
318 318
                 $className = match (true) {
319 319
                     $e instanceof NotFoundException => NotFoundException::class,
320 320
                     default => ContainerException::class,
@@ -323,19 +323,19 @@  discard block
 block discarded – undo
323 323
                     'Can\'t resolve `%s`.',
324 324
                     $alias,
325 325
                 )), previous: $e);
326
-            } finally {
326
+            }finally{
327 327
                 $this->tracer->pop(false);
328 328
             }
329 329
         }
330 330
 
331 331
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
332
-        try {
332
+        try{
333 333
             //No direct instructions how to construct class, make is automatically
334 334
             return $this->autowire(
335 335
                 new Ctx(alias: $alias, class: $alias, context: $context),
336 336
                 $parameters,
337 337
             );
338
-        } finally {
338
+        }finally{
339 339
             $this->tracer->pop(false);
340 340
         }
341 341
     }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
                 &&
357 357
                 (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class))
358 358
         ))
359
-        ) {
359
+        ){
360 360
             throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf(
361 361
                 'Can\'t resolve `%s`: undefined class or binding `%s`.',
362 362
                 $this->tracer->getRootAlias(),
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
         // Check scope name
386 386
         $ctx->reflection = new \ReflectionClass($instance);
387 387
         $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
388
-        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) {
388
+        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){
389 389
             throw new BadScopeException($scopeName, $instance::class);
390 390
         }
391 391
 
@@ -412,24 +412,24 @@  discard block
 block discarded – undo
412 412
         array $arguments,
413 413
     ): object {
414 414
         $class = $ctx->class;
415
-        try {
415
+        try{
416 416
             $ctx->reflection = $reflection = new \ReflectionClass($class);
417
-        } catch (\ReflectionException $e) {
417
+        }catch (\ReflectionException $e){
418 418
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
419 419
         }
420 420
 
421 421
         // Check scope name
422 422
         $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
423
-        if ($scope !== null && $scope !== $this->scope->getScopeName()) {
423
+        if ($scope !== null && $scope !== $this->scope->getScopeName()){
424 424
             throw new BadScopeException($scope, $class);
425 425
         }
426 426
 
427 427
         // We have to construct class using external injector when we know the exact context
428
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
428
+        if ($arguments === [] && $this->binder->hasInjector($class)){
429 429
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
430 430
         }
431 431
 
432
-        if (!$reflection->isInstantiable()) {
432
+        if (!$reflection->isInstantiable()){
433 433
             $itIs = match (true) {
434 434
                 $reflection->isEnum() => 'Enum',
435 435
                 $reflection->isAbstract() => 'Abstract class',
@@ -442,12 +442,12 @@  discard block
 block discarded – undo
442 442
 
443 443
         $constructor = $reflection->getConstructor();
444 444
 
445
-        if ($constructor !== null) {
446
-            try {
445
+        if ($constructor !== null){
446
+            try{
447 447
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
448 448
                 $this->tracer->push(true);
449 449
                 $args = $this->resolver->resolveArguments($constructor, $arguments);
450
-            } catch (ValidationException $e) {
450
+            }catch (ValidationException $e){
451 451
                 throw new ContainerException(
452 452
                     $this->tracer->combineTraceMessage(
453 453
                         \sprintf(
@@ -457,22 +457,22 @@  discard block
 block discarded – undo
457 457
                         )
458 458
                     ),
459 459
                 );
460
-            } finally {
460
+            }finally{
461 461
                 $this->tracer->pop(true);
462 462
                 $this->tracer->pop(false);
463 463
             }
464
-            try {
464
+            try{
465 465
                 // Using constructor with resolved arguments
466 466
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
467 467
                 $this->tracer->push(true);
468 468
                 $instance = new $class(...$args);
469
-            } catch (\TypeError $e) {
469
+            }catch (\TypeError $e){
470 470
                 throw new WrongTypeException($constructor, $e);
471
-            } finally {
471
+            }finally{
472 472
                 $this->tracer->pop(true);
473 473
                 $this->tracer->pop(false);
474 474
             }
475
-        } else {
475
+        }else{
476 476
             // No constructor specified
477 477
             $instance = $reflection->newInstance();
478 478
         }
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
         $instance = $this->runInflector($instance);
491 491
 
492 492
         //Declarative singletons
493
-        if ($this->isSingleton($ctx)) {
493
+        if ($this->isSingleton($ctx)){
494 494
             $this->state->singletons[$ctx->alias] = $instance;
495 495
         }
496 496
 
497 497
         // Register finalizer
498 498
         $finalizer = $this->getFinalizer($ctx, $instance);
499
-        if ($finalizer !== null) {
499
+        if ($finalizer !== null){
500 500
             $this->state->finalizers[] = $finalizer;
501 501
         }
502 502
 
@@ -508,12 +508,12 @@  discard block
 block discarded – undo
508 508
      */
509 509
     private function isSingleton(Ctx $ctx): bool
510 510
     {
511
-        if ($ctx->singleton === true) {
511
+        if ($ctx->singleton === true){
512 512
             return true;
513 513
         }
514 514
 
515 515
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
516
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
516
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class)){
517 517
             return true;
518 518
         }
519 519
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
          * @var Attribute\Finalize|null $attribute
528 528
          */
529 529
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
530
-        if ($attribute === null) {
530
+        if ($attribute === null){
531 531
             return null;
532 532
         }
533 533
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
     {
542 542
         $scope = $this->scope;
543 543
 
544
-        while ($scope !== null) {
545
-            foreach ($this->state->inflectors as $class => $inflectors) {
546
-                if ($instance instanceof $class) {
547
-                    foreach ($inflectors as $inflector) {
544
+        while ($scope !== null){
545
+            foreach ($this->state->inflectors as $class => $inflectors){
546
+                if ($instance instanceof $class){
547
+                    foreach ($inflectors as $inflector){
548 548
                         $instance = $inflector->getParametersCount() > 1
549 549
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
550 550
                             : ($inflector->inflector)($instance);
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
 
561 561
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
562 562
     {
563
-        try {
563
+        try{
564 564
             $this->resolver->validateArguments($reflection, $arguments);
565
-        } catch (\Throwable) {
565
+        }catch (\Throwable){
566 566
             return false;
567 567
         }
568 568
 
Please login to merge, or discard this patch.
src/Core/src/Config/Proxy.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         protected readonly string $interface,
14 14
         public readonly bool $singleton = false,
15
-    ) {
15
+    ){
16 16
     }
17 17
 
18 18
     public function __toString(): string
Please login to merge, or discard this patch.
src/Core/src/Config/DeprecationProxy.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@
 block discarded – undo
12 12
     public function __construct(
13 13
         string $interface,
14 14
         bool $singleton = false,
15
-        private readonly string|\BackedEnum|null $scope = null,
15
+        private readonly string | \BackedEnum | null $scope = null,
16 16
         private readonly ?string $version = null,
17 17
         private readonly ?string $message = null,
18
-    ) {
19
-        if (($scope === null || $version === null) && $message === null) {
18
+    ){
19
+        if (($scope === null || $version === null) && $message === null){
20 20
             throw new \InvalidArgumentException('Scope and version or custom message must be provided.');
21 21
         }
22 22
 
Please login to merge, or discard this patch.