Passed
Pull Request — master (#1221)
by Aleksei
12:41
created
src/Core/tests/ExceptionsTest.php 1 patch
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -208,10 +208,13 @@  discard block
 block discarded – undo
208 208
                 context: Parameter #1 [ <required> Spiral\Tests\Core\Fixtures\InvalidClass $class ]
209 209
             MARKDOWN;
210 210
 
211
-        try {
211
+        try
212
+        {
212 213
             $container->get(InvalidWithContainerInside::class);
213 214
             self::fail('Exception `ContainerException` expected');
214
-        } catch (ContainerException $e) {
215
+        }
216
+        catch (ContainerException $e)
217
+        {
215 218
             self::assertSame($expectedMessage, $e->getMessage());
216 219
         }
217 220
     }
@@ -234,9 +237,12 @@  discard block
 block discarded – undo
234 237
     {
235 238
         $container = new Container();
236 239
 
237
-        try {
240
+        try
241
+        {
238 242
             $container->get('invalid');
239
-        } catch (ContainerException $e) {
243
+        }
244
+        catch (ContainerException $e)
245
+        {
240 246
             self::assertSame(<<<MARKDOWN
241 247
                 Can't autowire `invalid`: class or injector not found.
242 248
                 Resolving trace:
@@ -267,9 +273,12 @@  discard block
 block discarded – undo
267 273
     {
268 274
         $this->expectException(ContainerException::class);
269 275
 
270
-        try {
276
+        try
277
+        {
271 278
             $container->get(ClassWithUndefinedDependency::class);
272
-        } catch (ContainerException $e) {
279
+        }
280
+        catch (ContainerException $e)
281
+        {
273 282
             self::assertSame($message, $e->getMessage());
274 283
 
275 284
             throw $e;
Please login to merge, or discard this patch.
src/Core/tests/Scope/ScopeAttributeTest.php 1 patch
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -166,7 +166,8 @@  discard block
 block discarded – undo
166 166
 
167 167
         $root = self::makeContainer();
168 168
 
169
-        try {
169
+        try
170
+        {
170 171
             $root->runScoped(static function (Container $c1): void {
171 172
                 $c1->runScoped(static function (Container $c2): void {
172 173
                     $c2->runScoped(static function (Container $c3): void {
@@ -174,7 +175,9 @@  discard block
 block discarded – undo
174 175
                     }, name: 'root');
175 176
                 });
176 177
             });
177
-        } catch (NamedScopeDuplicationException $e) {
178
+        }
179
+        catch (NamedScopeDuplicationException $e)
180
+        {
178 181
             self::assertSame('root', $e->getScope());
179 182
             throw $e;
180 183
         }
@@ -187,7 +190,8 @@  discard block
 block discarded – undo
187 190
     #[Group('scrutinizer-ignore')]
188 191
     public function testBadScopeException(): void
189 192
     {
190
-        try {
193
+        try
194
+        {
191 195
             $root = self::makeContainer();
192 196
             $root->runScoped(static function (Container $c1): void {
193 197
                 $c1->runScoped(static function (Container $c2): void {
@@ -196,7 +200,9 @@  discard block
 block discarded – undo
196 200
             }, name: 'bar');
197 201
 
198 202
             self::fail(BadScopeException::class . ' should be thrown');
199
-        } catch (BadScopeException $e) {
203
+        }
204
+        catch (BadScopeException $e)
205
+        {
200 206
             self::assertSame('foo', $e->getScope());
201 207
         }
202 208
     }
Please login to merge, or discard this patch.
src/Core/tests/Fixtures/PrivateConstructor.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@
 block discarded – undo
6 6
 
7 7
 final class PrivateConstructor
8 8
 {
9
-    private function __construct() {}
9
+    private function __construct()
10
+    {
11
+}
10 12
 
11 13
     private static function privateMethod(int $result): int
12 14
     {
Please login to merge, or discard this patch.
src/Core/src/Internal/Scope.php 1 patch
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,7 +17,8 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct(
19 19
         private readonly ?string $scopeName = null,
20
-    ) {}
20
+    ) {
21
+}
21 22
 
22 23
     public function getScopeName(): ?string
23 24
     {
@@ -39,9 +40,11 @@  discard block
 block discarded – undo
39 40
         $this->parentActor = $actor;
40 41
 
41 42
         // Check a scope with the same name is not already registered
42
-        if ($this->scopeName !== null) {
43
+        if ($this->scopeName !== null)
44
+        {
43 45
             $tmp = $this;
44
-            while ($tmp->parentScope !== null) {
46
+            while ($tmp->parentScope !== null)
47
+            {
45 48
                 $tmp = $tmp->parentScope;
46 49
                 $tmp->scopeName !== $this->scopeName ?: throw new NamedScopeDuplicationException($this->scopeName);
47 50
             }
@@ -64,7 +67,8 @@  discard block
 block discarded – undo
64 67
         $result = [$this->scopeName];
65 68
 
66 69
         $parent = $this;
67
-        while ($parent->parentScope !== null) {
70
+        while ($parent->parentScope !== null)
71
+        {
68 72
             $parent = $parent->parentScope;
69 73
             $result[] = $parent->scopeName;
70 74
         }
Please login to merge, or discard this patch.
src/Core/src/Internal/Invoker.php 1 patch
Braces   +23 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,26 +42,34 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function invoke(mixed $target, array $parameters = []): mixed
44 44
     {
45
-        if (\is_array($target) && isset($target[1])) {
45
+        if (\is_array($target) && isset($target[1]))
46
+        {
46 47
             // In a form of resolver and method
47 48
             [$resolver, $method] = $target;
48 49
 
49 50
             // Resolver instance or class name if the method is static (i.e. [ClassName::class, 'method'])
50
-            if (\is_string($resolver)) {
51
+            if (\is_string($resolver))
52
+            {
51 53
                 // Detect return type
52 54
                 $type = $this->actor->resolveType($resolver, $binding, $singleton, $injector);
53 55
 
54
-                if ($singleton === null) {
56
+                if ($singleton === null)
57
+                {
55 58
                     $type ??= $injector === null && $binding === null ? $resolver : null;
56 59
                     $resolver = \is_callable([$type, $method]) ? $type : $this->container->get($resolver);
57
-                } else {
60
+                }
61
+                else
62
+                {
58 63
                     $resolver = $singleton;
59 64
                 }
60 65
             }
61 66
 
62
-            try {
67
+            try
68
+            {
63 69
                 $method = new \ReflectionMethod($resolver, $method);
64
-            } catch (\ReflectionException $e) {
70
+            }
71
+            catch (\ReflectionException $e)
72
+            {
65 73
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
66 74
             }
67 75
 
@@ -72,14 +80,19 @@  discard block
 block discarded – undo
72 80
             );
73 81
         }
74 82
 
75
-        if (\is_string($target) && \is_callable($target)) {
83
+        if (\is_string($target) && \is_callable($target))
84
+        {
76 85
             $target = $target(...);
77 86
         }
78 87
 
79
-        if ($target instanceof \Closure) {
80
-            try {
88
+        if ($target instanceof \Closure)
89
+        {
90
+            try
91
+            {
81 92
                 $reflection = new \ReflectionFunction($target);
82
-            } catch (\ReflectionException $e) {
93
+            }
94
+            catch (\ReflectionException $e)
95
+            {
83 96
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
84 97
             }
85 98
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Tracer.php 1 patch
Braces   +13 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,19 +34,24 @@  discard block
 block discarded – undo
34 34
     public function push(bool $nextLevel, mixed ...$details): void
35 35
     {
36 36
         $trace = $details === [] ? null : new Trace($details);
37
-        if ($nextLevel || $this->traces === []) {
37
+        if ($nextLevel || $this->traces === [])
38
+        {
38 39
             $this->traces[] = $trace === null ? [] : [$trace];
39
-        } elseif ($trace !== null) {
40
+        }
41
+        elseif ($trace !== null)
42
+        {
40 43
             $this->traces[\array_key_last($this->traces)][] = $trace;
41 44
         }
42 45
     }
43 46
 
44 47
     public function pop(bool $previousLevel = false): void
45 48
     {
46
-        if ($this->traces === []) {
49
+        if ($this->traces === [])
50
+        {
47 51
             return;
48 52
         }
49
-        if ($previousLevel) {
53
+        if ($previousLevel)
54
+        {
50 55
             \array_pop($this->traces);
51 56
             return;
52 57
         }
@@ -72,7 +77,8 @@  discard block
 block discarded – undo
72 77
     {
73 78
         $result = [];
74 79
         $i = 0;
75
-        foreach ($blocks as $block) {
80
+        foreach ($blocks as $block)
81
+        {
76 82
             \array_push($result, ...self::blockToStringList($block, $i++));
77 83
         }
78 84
         return \implode("\n", $result);
@@ -92,7 +98,8 @@  discard block
 block discarded – undo
92 98
         // Separator
93 99
         $s = "\n";
94 100
         $nexPrefix = "$s$padding  ";
95
-        foreach ($items as $item) {
101
+        foreach ($items as $item)
102
+        {
96 103
             $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string) $item);
97 104
         }
98 105
         return $result;
Please login to merge, or discard this patch.
src/Core/src/Container.php 1 patch
Braces   +48 added lines, -22 removed lines patch added patch discarded remove patch
@@ -64,7 +64,8 @@  discard block
 block discarded – undo
64 64
         string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
65 65
         private Options $options = new Options(),
66 66
     ) {
67
-        if (\is_object($scopeName)) {
67
+        if (\is_object($scopeName))
68
+        {
68 69
             $scopeName = (string) $scopeName->value;
69 70
         }
70 71
 
@@ -166,23 +167,29 @@  discard block
 block discarded – undo
166 167
      */
167 168
     public function runScope(Scope|array $bindings, callable $scope): mixed
168 169
     {
169
-        if (!\is_array($bindings)) {
170
+        if (!\is_array($bindings))
171
+        {
170 172
             return $this->runIsolatedScope($bindings, $scope);
171 173
         }
172 174
 
173 175
         $binds = &$this->state->bindings;
174 176
         $singletons = &$this->state->singletons;
175 177
         $cleanup = $previous = $prevSin = [];
176
-        foreach ($bindings as $alias => $resolver) {
178
+        foreach ($bindings as $alias => $resolver)
179
+        {
177 180
             // Store previous bindings
178
-            if (isset($binds[$alias])) {
181
+            if (isset($binds[$alias]))
182
+            {
179 183
                 $previous[$alias] = $binds[$alias];
180
-            } else {
184
+            }
185
+            else
186
+            {
181 187
                 // Store bindings to be removed
182 188
                 $cleanup[] = $alias;
183 189
             }
184 190
             // Store previous singletons
185
-            if (isset($singletons[$alias])) {
191
+            if (isset($singletons[$alias]))
192
+            {
186 193
                 $prevSin[$alias] = $singletons[$alias];
187 194
                 unset($singletons[$alias]);
188 195
             }
@@ -190,21 +197,27 @@  discard block
 block discarded – undo
190 197
             $this->binder->bind($alias, $resolver);
191 198
         }
192 199
 
193
-        try {
200
+        try
201
+        {
194 202
             return ContainerScope::getContainer() !== $this
195 203
                 ? ContainerScope::runScope($this, $scope)
196 204
                 : $scope($this);
197
-        } finally {
205
+        }
206
+        finally
207
+        {
198 208
             // Remove new bindings
199
-            foreach ($cleanup as $alias) {
209
+            foreach ($cleanup as $alias)
210
+            {
200 211
                 unset($binds[$alias], $singletons[$alias]);
201 212
             }
202 213
             // Restore previous bindings
203
-            foreach ($previous as $alias => $resolver) {
214
+            foreach ($previous as $alias => $resolver)
215
+            {
204 216
                 $binds[$alias] = $resolver;
205 217
             }
206 218
             // Restore singletons
207
-            foreach ($prevSin as $alias => $instance) {
219
+            foreach ($prevSin as $alias => $instance)
220
+            {
208 221
                 $singletons[$alias] = $instance;
209 222
             }
210 223
         }
@@ -254,7 +267,8 @@  discard block
 block discarded – undo
254 267
      */
255 268
     public function bindSingleton(string $alias, string|array|callable|object $resolver, ?bool $force = null): void
256 269
     {
257
-        if ($force ?? $this->options->allowSingletonsRebinding) {
270
+        if ($force ?? $this->options->allowSingletonsRebinding)
271
+        {
258 272
             $this->binder->removeBinding($alias);
259 273
         }
260 274
 
@@ -338,8 +352,10 @@  discard block
 block discarded – undo
338 352
         ], $this->options);
339 353
 
340 354
         // Create container services
341
-        foreach ($container->config as $property => $class) {
342
-            if (\property_exists($container, $property)) {
355
+        foreach ($container->config as $property => $class)
356
+        {
357
+            if (\property_exists($container, $property))
358
+            {
343 359
                 $container->$property = $constructor->get($property, $class);
344 360
             }
345 361
         }
@@ -353,7 +369,8 @@  discard block
 block discarded – undo
353 369
     private function closeScope(): void
354 370
     {
355 371
         /** @psalm-suppress RedundantPropertyInitializationCheck */
356
-        if (!isset($this->scope)) {
372
+        if (!isset($this->scope))
373
+        {
357 374
             $this->destruct();
358 375
             return;
359 376
         }
@@ -362,10 +379,14 @@  discard block
 block discarded – undo
362 379
 
363 380
         // Run finalizers
364 381
         $errors = [];
365
-        foreach ($this->state->finalizers as $finalizer) {
366
-            try {
382
+        foreach ($this->state->finalizers as $finalizer)
383
+        {
384
+            try
385
+            {
367 386
                 $this->invoker->invoke($finalizer);
368
-            } catch (\Throwable $e) {
387
+            }
388
+            catch (\Throwable $e)
389
+            {
369 390
                 $errors[] = $e;
370 391
             }
371 392
         }
@@ -374,7 +395,8 @@  discard block
 block discarded – undo
374 395
         $this->destruct();
375 396
 
376 397
         // Throw collected errors
377
-        if ($errors !== []) {
398
+        if ($errors !== [])
399
+        {
378 400
             throw new FinalizersException($scopeName, $errors);
379 401
         }
380 402
     }
@@ -396,18 +418,22 @@  discard block
 block discarded – undo
396 418
         $container->scope->setParent($this, $this->scope, $this->actor);
397 419
 
398 420
         // Add specific bindings
399
-        foreach ($config->bindings as $alias => $resolver) {
421
+        foreach ($config->bindings as $alias => $resolver)
422
+        {
400 423
             $container->binder->bind($alias, $resolver);
401 424
         }
402 425
 
403 426
         return ContainerScope::runScope(
404 427
             $container,
405 428
             static function (self $container) use ($config, $closure): mixed {
406
-                try {
429
+                try
430
+                {
407 431
                     return $config->autowire
408 432
                         ? $container->invoke($closure)
409 433
                         : $closure($container);
410
-                } finally {
434
+                }
435
+                finally
436
+                {
411 437
                     $container->closeScope();
412 438
                 }
413 439
             },
Please login to merge, or discard this patch.
src/Core/src/Exception/Container/TracedContainerException.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,8 @@
 block discarded – undo
37 37
     public static function extendTracedException(string $message, array $traces, self $exception): static
38 38
     {
39 39
         $merge = $exception->containerTrace;
40
-        if ($traces !== [] && $merge !== []) {
40
+        if ($traces !== [] && $merge !== [])
41
+        {
41 42
             // merge lat element of $traces with first element of $merge
42 43
             \array_push($traces[\count($traces) - 1], ...$merge[0]);
43 44
             unset($merge[0]);
Please login to merge, or discard this patch.
src/Core/src/Exception/Container/AutowireException.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,4 +7,6 @@
 block discarded – undo
7 7
 /**
8 8
  * When class can not be created.
9 9
  */
10
-class AutowireException extends TracedContainerException {}
10
+class AutowireException extends TracedContainerException
11
+{
12
+}
Please login to merge, or discard this patch.