Test Failed
Pull Request — master (#1221)
by Aleksei
18:39
created
src/Core/tests/ExceptionsTest.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -208,10 +208,10 @@  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
             $container->get(InvalidWithContainerInside::class);
213 213
             self::fail('Exception `ContainerException` expected');
214
-        } catch (ContainerException $e) {
214
+        }catch (ContainerException $e){
215 215
             self::assertSame($expectedMessage, $e->getMessage());
216 216
         }
217 217
     }
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
     {
235 235
         $container = new Container();
236 236
 
237
-        try {
237
+        try{
238 238
             $container->get('invalid');
239
-        } catch (ContainerException $e) {
239
+        }catch (ContainerException $e){
240 240
             self::assertSame(<<<MARKDOWN
241 241
                 Can't autowire `invalid`: class or injector not found.
242 242
                 Resolving trace:
@@ -267,9 +267,9 @@  discard block
 block discarded – undo
267 267
     {
268 268
         $this->expectException(ContainerException::class);
269 269
 
270
-        try {
270
+        try{
271 271
             $container->get(ClassWithUndefinedDependency::class);
272
-        } catch (ContainerException $e) {
272
+        }catch (ContainerException $e){
273 273
             self::assertSame($message, $e->getMessage());
274 274
 
275 275
             throw $e;
Please login to merge, or discard this 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 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         $root = self::makeContainer();
168 168
 
169
-        try {
169
+        try{
170 170
             $root->runScoped(static function (Container $c1): void {
171 171
                 $c1->runScoped(static function (Container $c2): void {
172 172
                     $c2->runScoped(static function (Container $c3): void {
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                     }, name: 'root');
175 175
                 });
176 176
             });
177
-        } catch (NamedScopeDuplicationException $e) {
177
+        }catch (NamedScopeDuplicationException $e){
178 178
             self::assertSame('root', $e->getScope());
179 179
             throw $e;
180 180
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     #[Group('scrutinizer-ignore')]
188 188
     public function testBadScopeException(): void
189 189
     {
190
-        try {
190
+        try{
191 191
             $root = self::makeContainer();
192 192
             $root->runScoped(static function (Container $c1): void {
193 193
                 $c1->runScoped(static function (Container $c2): void {
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
                 });
196 196
             }, name: 'bar');
197 197
 
198
-            self::fail(BadScopeException::class . ' should be thrown');
199
-        } catch (BadScopeException $e) {
198
+            self::fail(BadScopeException::class.' should be thrown');
199
+        }catch (BadScopeException $e){
200 200
             self::assertSame('foo', $e->getScope());
201 201
         }
202 202
     }
Please login to merge, or discard this 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 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 final class PrivateConstructor
8 8
 {
9
-    private function __construct() {}
9
+    private function __construct(){}
10 10
 
11 11
     private static function privateMethod(int $result): int
12 12
     {
Please login to merge, or discard this 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/tests/InvokerTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $this->container->bindSingleton(Bucket::class, $bucket = new Bucket('foo'));
74 74
 
75
-        $result = $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']);
75
+        $result = $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']);
76 76
 
77 77
         self::assertSame($bucket, $result['bucket']);
78 78
         self::assertInstanceOf(SampleClass::class, $result['class']);
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function testCallStaticMethodWithoutInstantiationWithOvertypedFactory(): void
151 151
     {
152
-        $this->container->bind('foo', fn(): PrivateConstructor|SampleClass => throw new \Exception('Factory called'));
152
+        $this->container->bind('foo', fn(): PrivateConstructor | SampleClass => throw new \Exception('Factory called'));
153 153
         $this->expectExceptionMessage('Factory called');
154 154
         $this->container->invoke(['foo', 'publicMethod'], [42]);
155 155
     }
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $this->expectException(ArgumentResolvingException::class);
170 170
         $this->expectExceptionMessage('Unable to resolve required argument `name` when resolving');
171 171
 
172
-        $this->container->invoke(Storage::class . '::createBucket', ['name' => 'bar']);
172
+        $this->container->invoke(Storage::class.'::createBucket', ['name' => 'bar']);
173 173
     }
174 174
 
175 175
     public function testCallValidClosure(): void
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,23 +37,23 @@  discard block
 block discarded – undo
37 37
     public function make(
38 38
         string $alias,
39 39
         array $parameters = [],
40
-        \Stringable|string|null $context = null,
40
+        \Stringable | string | null $context = null,
41 41
         ?Tracer $tracer = null,
42 42
     ): mixed {
43
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
43
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){
44 44
             return $this->state->singletons[$alias];
45 45
         }
46 46
 
47 47
 
48 48
         $this->actor->resolveType($alias, $binding, $singleton, $injector, $actor, false);
49
-        if ($parameters === [] && $singleton !== null) {
49
+        if ($parameters === [] && $singleton !== null){
50 50
             return $singleton;
51 51
         }
52 52
 
53 53
         $tracer ??= new Tracer();
54 54
 
55 55
         // Resolve without binding
56
-        if ($binding === null) {
56
+        if ($binding === null){
57 57
             $tracer->push(
58 58
                 false,
59 59
                 action: 'autowire',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                 scope: $this->scope->getScopeName(),
62 62
                 context: $context,
63 63
             );
64
-            try {
64
+            try{
65 65
                 // No direct instructions how to construct class, make is automatically
66 66
                 return $this->actor->autowire(
67 67
                     new Ctx(alias: $alias, class: $alias, context: $context, singleton: $parameters === [] ? null : false),
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
                     $actor,
70 70
                     $tracer,
71 71
                 );
72
-            } finally {
72
+            }finally{
73 73
                 $tracer->pop(false);
74 74
             }
75 75
         }
76 76
 
77
-        try {
77
+        try{
78 78
             $tracer->push(
79 79
                 false,
80 80
                 action: 'resolve from binding',
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 
88 88
             // unset($this->state->bindings[$alias]);
89 89
             return $actor->resolveBinding($binding, $alias, $context, $parameters, $tracer);
90
-        } finally {
90
+        }finally{
91 91
             // $this->state->bindings[$alias] ??= $binding;
92 92
             $tracer->pop(true);
93 93
             $tracer->pop(false);
Please login to merge, or discard this patch.
Braces   +16 added lines, -7 removed lines patch added patch discarded remove patch
@@ -40,20 +40,23 @@  discard block
 block discarded – undo
40 40
         \Stringable|string|null $context = null,
41 41
         ?Tracer $tracer = null,
42 42
     ): mixed {
43
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
43
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons))
44
+        {
44 45
             return $this->state->singletons[$alias];
45 46
         }
46 47
 
47 48
 
48 49
         $this->actor->resolveType($alias, $binding, $singleton, $injector, $actor, false);
49
-        if ($parameters === [] && $singleton !== null) {
50
+        if ($parameters === [] && $singleton !== null)
51
+        {
50 52
             return $singleton;
51 53
         }
52 54
 
53 55
         $tracer ??= new Tracer();
54 56
 
55 57
         // Resolve without binding
56
-        if ($binding === null) {
58
+        if ($binding === null)
59
+        {
57 60
             $tracer->push(
58 61
                 false,
59 62
                 action: 'autowire',
@@ -61,7 +64,8 @@  discard block
 block discarded – undo
61 64
                 scope: $this->scope->getScopeName(),
62 65
                 context: $context,
63 66
             );
64
-            try {
67
+            try
68
+            {
65 69
                 // No direct instructions how to construct class, make is automatically
66 70
                 return $this->actor->autowire(
67 71
                     new Ctx(alias: $alias, class: $alias, context: $context, singleton: $parameters === [] ? null : false),
@@ -69,12 +73,15 @@  discard block
 block discarded – undo
69 73
                     $actor,
70 74
                     $tracer,
71 75
                 );
72
-            } finally {
76
+            }
77
+            finally
78
+            {
73 79
                 $tracer->pop(false);
74 80
             }
75 81
         }
76 82
 
77
-        try {
83
+        try
84
+        {
78 85
             $tracer->push(
79 86
                 false,
80 87
                 action: 'resolve from binding',
@@ -87,7 +94,9 @@  discard block
 block discarded – undo
87 94
 
88 95
             // unset($this->state->bindings[$alias]);
89 96
             return $actor->resolveBinding($binding, $alias, $context, $parameters, $tracer);
90
-        } finally {
97
+        }
98
+        finally
99
+        {
91 100
             // $this->state->bindings[$alias] ??= $binding;
92 101
             $tracer->pop(true);
93 102
             $tracer->pop(false);
Please login to merge, or discard this patch.
src/Core/src/Internal/Scope.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  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
     public function getScopeName(): ?string
23 23
     {
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
         $this->parentActor = $actor;
40 40
 
41 41
         // Check a scope with the same name is not already registered
42
-        if ($this->scopeName !== null) {
42
+        if ($this->scopeName !== null){
43 43
             $tmp = $this;
44
-            while ($tmp->parentScope !== null) {
44
+            while ($tmp->parentScope !== null){
45 45
                 $tmp = $tmp->parentScope;
46 46
                 $tmp->scopeName !== $this->scopeName ?: throw new NamedScopeDuplicationException($this->scopeName);
47 47
             }
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $result = [$this->scopeName];
65 65
 
66 66
         $parent = $this;
67
-        while ($parent->parentScope !== null) {
67
+        while ($parent->parentScope !== null){
68 68
             $parent = $parent->parentScope;
69 69
             $result[] = $parent->scopeName;
70 70
         }
Please login to merge, or discard this 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 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,26 +42,26 @@  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
             // In a form of resolver and method
47 47
             [$resolver, $method] = $target;
48 48
 
49 49
             // Resolver instance or class name if the method is static (i.e. [ClassName::class, 'method'])
50
-            if (\is_string($resolver)) {
50
+            if (\is_string($resolver)){
51 51
                 // Detect return type
52 52
                 $type = $this->actor->resolveType($resolver, $binding, $singleton, $injector);
53 53
 
54
-                if ($singleton === null) {
54
+                if ($singleton === null){
55 55
                     $type ??= $injector === null && $binding === null ? $resolver : null;
56 56
                     $resolver = \is_callable([$type, $method]) ? $type : $this->container->get($resolver);
57
-                } else {
57
+                }else{
58 58
                     $resolver = $singleton;
59 59
                 }
60 60
             }
61 61
 
62
-            try {
62
+            try{
63 63
                 $method = new \ReflectionMethod($resolver, $method);
64
-            } catch (\ReflectionException $e) {
64
+            }catch (\ReflectionException $e){
65 65
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
66 66
             }
67 67
 
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
             );
73 73
         }
74 74
 
75
-        if (\is_string($target) && \is_callable($target)) {
75
+        if (\is_string($target) && \is_callable($target)){
76 76
             $target = $target(...);
77 77
         }
78 78
 
79
-        if ($target instanceof \Closure) {
80
-            try {
79
+        if ($target instanceof \Closure){
80
+            try{
81 81
                 $reflection = new \ReflectionFunction($target);
82
-            } catch (\ReflectionException $e) {
82
+            }catch (\ReflectionException $e){
83 83
                 throw new ContainerException($e->getMessage(), $e->getCode(), $e);
84 84
             }
85 85
 
Please login to merge, or discard this 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/Actor.php 2 patches
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function resolveType(
78 78
         string $alias,
79
-        ?Binding &$binding = null,
79
+        ?Binding & $binding = null,
80 80
         ?object &$singleton = null,
81 81
         ?object &$injector = null,
82 82
         ?self &$actor = null,
@@ -85,21 +85,21 @@  discard block
 block discarded – undo
85 85
         // Aliases to prevent circular dependencies
86 86
         $as = [];
87 87
         $actor = $this;
88
-        do {
88
+        do{
89 89
             $bindings = &$actor->state->bindings;
90 90
             $singletons = &$actor->state->singletons;
91 91
             $injectors = &$actor->state->injectors;
92
-            if (\array_key_exists($alias, $singletons)) {
92
+            if (\array_key_exists($alias, $singletons)){
93 93
                 $singleton = $singletons[$alias];
94 94
                 $binding = $bindings[$alias] ?? null;
95 95
                 $injector = $injectors[$alias] ?? null;
96 96
                 return \is_object($singleton::class) ? $singleton::class : null;
97 97
             }
98 98
 
99
-            if (\array_key_exists($alias, $bindings)) {
99
+            if (\array_key_exists($alias, $bindings)){
100 100
                 $binding = $bindings[$alias];
101
-                if ($followAlias && $binding::class === Alias::class) {
102
-                    if ($binding->alias === $alias) {
101
+                if ($followAlias && $binding::class === Alias::class){
102
+                    if ($binding->alias === $alias){
103 103
                         break;
104 104
                     }
105 105
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
                 return $binding->getReturnClass();
115 115
             }
116 116
 
117
-            if (\array_key_exists($alias, $injectors)) {
117
+            if (\array_key_exists($alias, $injectors)){
118 118
                 $injector = $injectors[$alias];
119 119
                 $binding = $bindings[$alias] ?? null;
120 120
                 return $alias;
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
 
123 123
             // Go to parent scope
124 124
             $parent = $actor->scope->getParentActor();
125
-            if ($parent === null) {
125
+            if ($parent === null){
126 126
                 break;
127 127
             }
128 128
 
129 129
             $actor = $parent;
130
-        } while (true);
130
+        }while (true);
131 131
 
132 132
         return \class_exists($alias) ? $alias : null;
133 133
     }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     public function resolveBinding(
136 136
         object $binding,
137 137
         string $alias,
138
-        \Stringable|string|null $context,
138
+        \Stringable | string | null $context,
139 139
         array $arguments,
140 140
         Tracer $tracer,
141 141
     ): mixed {
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer)
193 193
     {
194 194
         $context = $ctx->context;
195
-        try {
195
+        try{
196 196
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
197
-        } catch (\ReflectionException $e) {
197
+        }catch (\ReflectionException $e){
198 198
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
199 199
         }
200 200
 
201 201
         $injector = $binding->injector;
202 202
 
203
-        try {
203
+        try{
204 204
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
205 205
 
206
-            if (!$injectorInstance instanceof InjectorInterface) {
206
+            if (!$injectorInstance instanceof InjectorInterface){
207 207
                 throw new InjectionException(
208 208
                     \sprintf(
209 209
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
             static $cache = [];
218 218
             $extended = $cache[$injectorInstance::class] ??= (
219 219
             static fn(\ReflectionType $type): bool =>
220
-                $type::class === \ReflectionUnionType::class || (string) $type === 'mixed'
220
+                $type::class === \ReflectionUnionType::class || (string)$type === 'mixed'
221 221
             )(
222 222
                 ($refMethod = new \ReflectionMethod($injectorInstance, 'createInjection'))
223 223
                     ->getParameters()[1]->getType()
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
             $instance = $injectorInstance->createInjection($reflection, match (true) {
228 228
                 $asIs => $context,
229 229
                 $context instanceof \ReflectionParameter => $context->getName(),
230
-                default => (string) $context,
230
+                default => (string)$context,
231 231
             });
232 232
 
233
-            if (!$reflection->isInstance($instance)) {
233
+            if (!$reflection->isInstance($instance)){
234 234
                 throw new InjectionException(
235 235
                     \sprintf(
236 236
                         "Invalid injection response for '%s'.",
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
             }
241 241
 
242 242
             return $instance;
243
-        } catch (TracedContainerException $e) {
243
+        }catch (TracedContainerException $e){
244 244
             throw isset($injectorInstance) ? $e : $e::extendTracedException(\sprintf(
245 245
                 'Can\'t resolve `%s`.',
246 246
                 $tracer->getRootAlias(),
247 247
             ), $tracer->getTraces(), $e);
248
-        } finally {
248
+        }finally{
249 249
             $this->state->bindings[$ctx->class] ??= $binding;
250 250
         }
251 251
     }
@@ -253,22 +253,22 @@  discard block
 block discarded – undo
253 253
     private function resolveAlias(
254 254
         Config\Alias $binding,
255 255
         string $alias,
256
-        \Stringable|string|null $context,
256
+        \Stringable | string | null $context,
257 257
         array $arguments,
258 258
         Tracer $tracer,
259 259
     ): mixed {
260
-        if ($binding->alias === $alias) {
260
+        if ($binding->alias === $alias){
261 261
             $instance = $this->autowire(
262 262
                 new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []),
263 263
                 $arguments,
264 264
                 $this,
265 265
                 $tracer,
266 266
             );
267
-        } else {
268
-            try {
267
+        }else{
268
+            try{
269 269
                 //Binding is pointing to something else
270 270
                 $instance = $this->factory->make($binding->alias, $arguments, $context);
271
-            } catch (TracedContainerException $e) {
271
+            }catch (TracedContainerException $e){
272 272
                 throw $e::extendTracedException(
273 273
                     $alias === $tracer->getRootAlias()
274 274
                         ? "Can't resolve `{$alias}`."
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
         return $instance;
286 286
     }
287 287
 
288
-    private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed
288
+    private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable | string | null $context): mixed
289 289
     {
290
-        if ($context instanceof RetryContext) {
290
+        if ($context instanceof RetryContext){
291 291
             return $binding->fallbackFactory === null
292 292
                 ? throw new RecursiveProxyException(
293 293
                     $alias,
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 
299 299
         $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy());
300 300
 
301
-        if ($binding->singleton) {
301
+        if ($binding->singleton){
302 302
             $this->state->singletons[$alias] = $result;
303 303
         }
304 304
 
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
     private function resolveShared(
309 309
         Config\Shared $binding,
310 310
         string $alias,
311
-        \Stringable|string|null $context,
311
+        \Stringable | string | null $context,
312 312
         array $arguments,
313 313
         Tracer $tracer,
314 314
     ): object {
315
-        if ($arguments !== []) {
315
+        if ($arguments !== []){
316 316
             // Avoid singleton cache
317 317
             return $this->createInstance(
318 318
                 new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false),
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
             );
323 323
         }
324 324
 
325
-        if ($binding->singleton) {
325
+        if ($binding->singleton){
326 326
             $this->state->singletons[$alias] = $binding->value;
327 327
         }
328 328
 
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
     private function resolveAutowire(
333 333
         Config\Autowire $binding,
334 334
         string $alias,
335
-        \Stringable|string|null $context,
335
+        \Stringable | string | null $context,
336 336
         array $arguments,
337 337
         Tracer $tracer,
338 338
     ): mixed {
339 339
         $target = $binding->autowire->alias;
340 340
         $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
341 341
 
342
-        if ($alias === $target) {
342
+        if ($alias === $target){
343 343
             $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer);
344
-        } else {
344
+        }else{
345 345
             $instance = $binding->autowire->resolve($this->factory, $arguments);
346 346
             $this->validateConstraint($instance, $ctx);
347 347
         }
@@ -350,24 +350,24 @@  discard block
 block discarded – undo
350 350
     }
351 351
 
352 352
     private function resolveFactory(
353
-        Config\Factory|Config\DeferredFactory $binding,
353
+        Config\Factory | Config\DeferredFactory $binding,
354 354
         string $alias,
355
-        \Stringable|string|null $context,
355
+        \Stringable | string | null $context,
356 356
         array $arguments,
357 357
         Tracer $tracer,
358 358
     ): mixed {
359 359
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
360
-        try {
360
+        try{
361 361
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
362 362
                 ? ($binding->factory)()
363 363
                 : $this->invoker->invoke($binding->factory, $arguments);
364
-        } catch (NotCallableException $e) {
364
+        }catch (NotCallableException $e){
365 365
             throw TracedContainerException::createWithTrace(
366 366
                 \sprintf('Invalid callable binding for `%s`.', $ctx->alias),
367 367
                 $tracer->getTraces(),
368 368
                 $e,
369 369
             );
370
-        } catch (TracedContainerException $e) {
370
+        }catch (TracedContainerException $e){
371 371
             throw $e::extendTracedException(
372 372
                 \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()),
373 373
                 $tracer->getTraces(),
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
             );
376 376
         }
377 377
 
378
-        if (\is_object($instance)) {
378
+        if (\is_object($instance)){
379 379
             $this->validateConstraint($instance, $ctx);
380 380
             return $this->registerInstance($ctx, $instance);
381 381
         }
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
     private function resolveWeakReference(
387 387
         Config\WeakReference $binding,
388 388
         string $alias,
389
-        \Stringable|string|null $context,
389
+        \Stringable | string | null $context,
390 390
         array $arguments,
391 391
         Tracer $tracer,
392 392
     ): ?object {
393 393
         $avoidCache = $arguments !== [];
394 394
 
395
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
396
-            try {
395
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){
396
+            try{
397 397
                 $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context);
398 398
 
399 399
                 $object = $this->createInstance(
@@ -402,17 +402,17 @@  discard block
 block discarded – undo
402 402
                     $this,
403 403
                     $tracer,
404 404
                 );
405
-                if ($avoidCache) {
405
+                if ($avoidCache){
406 406
                     return $object;
407 407
                 }
408 408
                 $binding->reference = \WeakReference::create($object);
409
-            } catch (\Throwable) {
409
+            }catch (\Throwable){
410 410
                 throw ContainerException::createWithTrace(\sprintf(
411 411
                     'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.',
412 412
                     $tracer->getRootAlias(),
413 413
                     $alias,
414 414
                 ), $tracer->getTraces());
415
-            } finally {
415
+            }finally{
416 416
                 $tracer->pop();
417 417
             }
418 418
         }
@@ -428,13 +428,13 @@  discard block
 block discarded – undo
428 428
         object $instance,
429 429
         Ctx $ctx,
430 430
     ): void {
431
-        if ($this->options->checkScope) {
431
+        if ($this->options->checkScope){
432 432
             // Check scope name
433 433
             $ctx->reflection ??= new \ReflectionClass($instance);
434 434
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
435
-            if ($scopeName !== null) {
435
+            if ($scopeName !== null){
436 436
                 $scope = $this->scope;
437
-                while ($scope->getScopeName() !== $scopeName) {
437
+                while ($scope->getScopeName() !== $scopeName){
438 438
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
439 439
                 }
440 440
             }
@@ -461,26 +461,26 @@  discard block
 block discarded – undo
461 461
         Tracer $tracer,
462 462
     ): object {
463 463
         $class = $ctx->class;
464
-        try {
464
+        try{
465 465
             $ctx->reflection = $reflection = new \ReflectionClass($class);
466
-        } catch (\ReflectionException $e) {
466
+        }catch (\ReflectionException $e){
467 467
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
468 468
         }
469 469
 
470 470
         // Check Scope attribute
471 471
         $actor = $fallbackActor ?? $this;
472
-        if ($this->options->checkScope) { # todo
472
+        if ($this->options->checkScope){ # todo
473 473
             $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null);
474
-            if ($ar !== null) {
474
+            if ($ar !== null){
475 475
                 /** @var Attribute\Scope $attr */
476 476
                 $attr = $ar->newInstance();
477 477
                 $scope = $this->scope;
478 478
                 $actor = $this;
479 479
                 // Go through all parent scopes
480 480
                 $needed = $actor;
481
-                while ($attr->name !== $scope->getScopeName()) {
481
+                while ($attr->name !== $scope->getScopeName()){
482 482
                     $needed = $scope->getParentActor();
483
-                    if ($needed === null) {
483
+                    if ($needed === null){
484 484
                         throw new BadScopeException($attr->name, $class);
485 485
                     }
486 486
 
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
         } # todo
494 494
 
495 495
         // We have to construct class using external injector when we know the exact context
496
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
496
+        if ($arguments === [] && $this->binder->hasInjector($class)){
497 497
             return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer);
498 498
         }
499 499
 
500
-        if (!$reflection->isInstantiable()) {
500
+        if (!$reflection->isInstantiable()){
501 501
             $itIs = match (true) {
502 502
                 $reflection->isEnum() => 'Enum',
503 503
                 $reflection->isAbstract() => 'Abstract class',
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 
512 512
         $constructor = $reflection->getConstructor();
513 513
 
514
-        if ($constructor !== null) {
515
-            try {
514
+        if ($constructor !== null){
515
+            try{
516 516
                 $newScope = $this !== $actor;
517 517
                 $debug = [
518 518
                     'action' => 'resolve arguments',
@@ -526,39 +526,39 @@  discard block
 block discarded – undo
526 526
                 $tracer->push($newScope, ...$debug);
527 527
                 $tracer->push(true);
528 528
                 $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments);
529
-            } catch (ValidationException $e) {
529
+            }catch (ValidationException $e){
530 530
                 throw TracedContainerException::createWithTrace(\sprintf(
531 531
                     'Can\'t resolve `%s`. %s',
532 532
                     $tracer->getRootAlias(),
533 533
                     $e->getMessage(),
534 534
                 ), $tracer->getTraces());
535
-            } catch (TracedContainerException $e) {
535
+            }catch (TracedContainerException $e){
536 536
                 throw $e::extendTracedException(\sprintf(
537 537
                     'Can\'t resolve `%s`.',
538 538
                     $tracer->getRootAlias(),
539 539
                 ), $tracer->getTraces(), $e);
540
-            } finally {
540
+            }finally{
541 541
                 $tracer->pop($newScope);
542 542
                 $tracer->pop(false);
543 543
             }
544
-            try {
544
+            try{
545 545
                 // Using constructor with resolved arguments
546 546
                 $tracer->push(false, call: "$class::__construct", arguments: $args);
547 547
                 $tracer->push(true);
548 548
                 $instance = new $class(...$args);
549
-            } catch (\TypeError $e) {
549
+            }catch (\TypeError $e){
550 550
                 throw new WrongTypeException($constructor, $e);
551
-            } catch (TracedContainerException $e) {
551
+            }catch (TracedContainerException $e){
552 552
                 throw $e::extendTracedException(\sprintf(
553 553
                     'Can\'t resolve `%s`: failed constructing `%s`.',
554 554
                     $tracer->getRootAlias(),
555 555
                     $class,
556 556
                 ), $tracer->getTraces(), $e);
557
-            } finally {
557
+            }finally{
558 558
                 $tracer->pop(true);
559 559
                 $tracer->pop(false);
560 560
             }
561
-        } else {
561
+        }else{
562 562
             // No constructor specified
563 563
             $instance = $reflection->newInstance();
564 564
         }
@@ -590,12 +590,12 @@  discard block
 block discarded – undo
590 590
      */
591 591
     private function isSingleton(Ctx $ctx): bool
592 592
     {
593
-        if (is_bool($ctx->singleton)) {
593
+        if (is_bool($ctx->singleton)){
594 594
             return $ctx->singleton;
595 595
         }
596 596
 
597 597
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
598
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
598
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class)){
599 599
             return true;
600 600
         }
601 601
 
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
          * @var Attribute\Finalize|null $attribute
610 610
          */
611 611
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
612
-        if ($attribute === null) {
612
+        if ($attribute === null){
613 613
             return null;
614 614
         }
615 615
 
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
     {
624 624
         $scope = $this->scope;
625 625
 
626
-        while ($scope !== null) {
627
-            foreach ($this->state->inflectors as $class => $inflectors) {
628
-                if ($instance instanceof $class) {
629
-                    foreach ($inflectors as $inflector) {
626
+        while ($scope !== null){
627
+            foreach ($this->state->inflectors as $class => $inflectors){
628
+                if ($instance instanceof $class){
629
+                    foreach ($inflectors as $inflector){
630 630
                         $instance = $inflector->getParametersCount() > 1
631 631
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
632 632
                             : ($inflector->inflector)($instance);
@@ -642,9 +642,9 @@  discard block
 block discarded – undo
642 642
 
643 643
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
644 644
     {
645
-        try {
645
+        try{
646 646
             $this->resolver->validateArguments($reflection, $arguments);
647
-        } catch (\Throwable) {
647
+        }catch (\Throwable){
648 648
             return false;
649 649
         }
650 650
 
Please login to merge, or discard this patch.
Braces   +146 added lines, -63 removed lines patch added patch discarded remove patch
@@ -85,21 +85,26 @@  discard block
 block discarded – undo
85 85
         // Aliases to prevent circular dependencies
86 86
         $as = [];
87 87
         $actor = $this;
88
-        do {
88
+        do
89
+        {
89 90
             $bindings = &$actor->state->bindings;
90 91
             $singletons = &$actor->state->singletons;
91 92
             $injectors = &$actor->state->injectors;
92
-            if (\array_key_exists($alias, $singletons)) {
93
+            if (\array_key_exists($alias, $singletons))
94
+            {
93 95
                 $singleton = $singletons[$alias];
94 96
                 $binding = $bindings[$alias] ?? null;
95 97
                 $injector = $injectors[$alias] ?? null;
96 98
                 return \is_object($singleton::class) ? $singleton::class : null;
97 99
             }
98 100
 
99
-            if (\array_key_exists($alias, $bindings)) {
101
+            if (\array_key_exists($alias, $bindings))
102
+            {
100 103
                 $binding = $bindings[$alias];
101
-                if ($followAlias && $binding::class === Alias::class) {
102
-                    if ($binding->alias === $alias) {
104
+                if ($followAlias && $binding::class === Alias::class)
105
+                {
106
+                    if ($binding->alias === $alias)
107
+                    {
103 108
                         break;
104 109
                     }
105 110
 
@@ -114,7 +119,8 @@  discard block
 block discarded – undo
114 119
                 return $binding->getReturnClass();
115 120
             }
116 121
 
117
-            if (\array_key_exists($alias, $injectors)) {
122
+            if (\array_key_exists($alias, $injectors))
123
+            {
118 124
                 $injector = $injectors[$alias];
119 125
                 $binding = $bindings[$alias] ?? null;
120 126
                 return $alias;
@@ -122,7 +128,8 @@  discard block
 block discarded – undo
122 128
 
123 129
             // Go to parent scope
124 130
             $parent = $actor->scope->getParentActor();
125
-            if ($parent === null) {
131
+            if ($parent === null)
132
+            {
126 133
                 break;
127 134
             }
128 135
 
@@ -192,18 +199,23 @@  discard block
 block discarded – undo
192 199
     private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments, Tracer $tracer)
193 200
     {
194 201
         $context = $ctx->context;
195
-        try {
202
+        try
203
+        {
196 204
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
197
-        } catch (\ReflectionException $e) {
205
+        }
206
+        catch (\ReflectionException $e)
207
+        {
198 208
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
199 209
         }
200 210
 
201 211
         $injector = $binding->injector;
202 212
 
203
-        try {
213
+        try
214
+        {
204 215
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
205 216
 
206
-            if (!$injectorInstance instanceof InjectorInterface) {
217
+            if (!$injectorInstance instanceof InjectorInterface)
218
+            {
207 219
                 throw new InjectionException(
208 220
                     \sprintf(
209 221
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -230,7 +242,8 @@  discard block
 block discarded – undo
230 242
                 default => (string) $context,
231 243
             });
232 244
 
233
-            if (!$reflection->isInstance($instance)) {
245
+            if (!$reflection->isInstance($instance))
246
+            {
234 247
                 throw new InjectionException(
235 248
                     \sprintf(
236 249
                         "Invalid injection response for '%s'.",
@@ -240,12 +253,16 @@  discard block
 block discarded – undo
240 253
             }
241 254
 
242 255
             return $instance;
243
-        } catch (TracedContainerException $e) {
256
+        }
257
+        catch (TracedContainerException $e)
258
+        {
244 259
             throw isset($injectorInstance) ? $e : $e::extendTracedException(\sprintf(
245 260
                 'Can\'t resolve `%s`.',
246 261
                 $tracer->getRootAlias(),
247 262
             ), $tracer->getTraces(), $e);
248
-        } finally {
263
+        }
264
+        finally
265
+        {
249 266
             $this->state->bindings[$ctx->class] ??= $binding;
250 267
         }
251 268
     }
@@ -257,18 +274,24 @@  discard block
 block discarded – undo
257 274
         array $arguments,
258 275
         Tracer $tracer,
259 276
     ): mixed {
260
-        if ($binding->alias === $alias) {
277
+        if ($binding->alias === $alias)
278
+        {
261 279
             $instance = $this->autowire(
262 280
                 new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton && $arguments === []),
263 281
                 $arguments,
264 282
                 $this,
265 283
                 $tracer,
266 284
             );
267
-        } else {
268
-            try {
285
+        }
286
+        else
287
+        {
288
+            try
289
+            {
269 290
                 //Binding is pointing to something else
270 291
                 $instance = $this->factory->make($binding->alias, $arguments, $context);
271
-            } catch (TracedContainerException $e) {
292
+            }
293
+            catch (TracedContainerException $e)
294
+            {
272 295
                 throw $e::extendTracedException(
273 296
                     $alias === $tracer->getRootAlias()
274 297
                         ? "Can't resolve `{$alias}`."
@@ -287,7 +310,8 @@  discard block
 block discarded – undo
287 310
 
288 311
     private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed
289 312
     {
290
-        if ($context instanceof RetryContext) {
313
+        if ($context instanceof RetryContext)
314
+        {
291 315
             return $binding->fallbackFactory === null
292 316
                 ? throw new RecursiveProxyException(
293 317
                     $alias,
@@ -298,7 +322,8 @@  discard block
 block discarded – undo
298 322
 
299 323
         $result = Proxy::create(new \ReflectionClass($binding->getReturnClass()), $context, new Attribute\Proxy());
300 324
 
301
-        if ($binding->singleton) {
325
+        if ($binding->singleton)
326
+        {
302 327
             $this->state->singletons[$alias] = $result;
303 328
         }
304 329
 
@@ -312,7 +337,8 @@  discard block
 block discarded – undo
312 337
         array $arguments,
313 338
         Tracer $tracer,
314 339
     ): object {
315
-        if ($arguments !== []) {
340
+        if ($arguments !== [])
341
+        {
316 342
             // Avoid singleton cache
317 343
             return $this->createInstance(
318 344
                 new Ctx(alias: $alias, class: $binding->value::class, context: $context, singleton: false),
@@ -322,7 +348,8 @@  discard block
 block discarded – undo
322 348
             );
323 349
         }
324 350
 
325
-        if ($binding->singleton) {
351
+        if ($binding->singleton)
352
+        {
326 353
             $this->state->singletons[$alias] = $binding->value;
327 354
         }
328 355
 
@@ -339,9 +366,12 @@  discard block
 block discarded – undo
339 366
         $target = $binding->autowire->alias;
340 367
         $ctx = new Ctx(alias: $alias, class: $target, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
341 368
 
342
-        if ($alias === $target) {
369
+        if ($alias === $target)
370
+        {
343 371
             $instance = $this->autowire($ctx, \array_merge($binding->autowire->parameters, $arguments), $this, $tracer);
344
-        } else {
372
+        }
373
+        else
374
+        {
345 375
             $instance = $binding->autowire->resolve($this->factory, $arguments);
346 376
             $this->validateConstraint($instance, $ctx);
347 377
         }
@@ -357,17 +387,22 @@  discard block
 block discarded – undo
357 387
         Tracer $tracer,
358 388
     ): mixed {
359 389
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton && $arguments === [] ?: null);
360
-        try {
390
+        try
391
+        {
361 392
             $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0
362 393
                 ? ($binding->factory)()
363 394
                 : $this->invoker->invoke($binding->factory, $arguments);
364
-        } catch (NotCallableException $e) {
395
+        }
396
+        catch (NotCallableException $e)
397
+        {
365 398
             throw TracedContainerException::createWithTrace(
366 399
                 \sprintf('Invalid callable binding for `%s`.', $ctx->alias),
367 400
                 $tracer->getTraces(),
368 401
                 $e,
369 402
             );
370
-        } catch (TracedContainerException $e) {
403
+        }
404
+        catch (TracedContainerException $e)
405
+        {
371 406
             throw $e::extendTracedException(
372 407
                 \sprintf("Can't resolve `%s`: factory invocation failed.", $tracer->getRootAlias()),
373 408
                 $tracer->getTraces(),
@@ -375,7 +410,8 @@  discard block
 block discarded – undo
375 410
             );
376 411
         }
377 412
 
378
-        if (\is_object($instance)) {
413
+        if (\is_object($instance))
414
+        {
379 415
             $this->validateConstraint($instance, $ctx);
380 416
             return $this->registerInstance($ctx, $instance);
381 417
         }
@@ -392,8 +428,10 @@  discard block
 block discarded – undo
392 428
     ): ?object {
393 429
         $avoidCache = $arguments !== [];
394 430
 
395
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
396
-            try {
431
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias))
432
+        {
433
+            try
434
+            {
397 435
                 $tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context);
398 436
 
399 437
                 $object = $this->createInstance(
@@ -402,17 +440,22 @@  discard block
 block discarded – undo
402 440
                     $this,
403 441
                     $tracer,
404 442
                 );
405
-                if ($avoidCache) {
443
+                if ($avoidCache)
444
+                {
406 445
                     return $object;
407 446
                 }
408 447
                 $binding->reference = \WeakReference::create($object);
409
-            } catch (\Throwable) {
448
+            }
449
+            catch (\Throwable)
450
+            {
410 451
                 throw ContainerException::createWithTrace(\sprintf(
411 452
                     'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.',
412 453
                     $tracer->getRootAlias(),
413 454
                     $alias,
414 455
                 ), $tracer->getTraces());
415
-            } finally {
456
+            }
457
+            finally
458
+            {
416 459
                 $tracer->pop();
417 460
             }
418 461
         }
@@ -428,13 +471,16 @@  discard block
 block discarded – undo
428 471
         object $instance,
429 472
         Ctx $ctx,
430 473
     ): void {
431
-        if ($this->options->checkScope) {
474
+        if ($this->options->checkScope)
475
+        {
432 476
             // Check scope name
433 477
             $ctx->reflection ??= new \ReflectionClass($instance);
434 478
             $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name;
435
-            if ($scopeName !== null) {
479
+            if ($scopeName !== null)
480
+            {
436 481
                 $scope = $this->scope;
437
-                while ($scope->getScopeName() !== $scopeName) {
482
+                while ($scope->getScopeName() !== $scopeName)
483
+                {
438 484
                     $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class);
439 485
                 }
440 486
             }
@@ -461,26 +507,34 @@  discard block
 block discarded – undo
461 507
         Tracer $tracer,
462 508
     ): object {
463 509
         $class = $ctx->class;
464
-        try {
510
+        try
511
+        {
465 512
             $ctx->reflection = $reflection = new \ReflectionClass($class);
466
-        } catch (\ReflectionException $e) {
513
+        }
514
+        catch (\ReflectionException $e)
515
+        {
467 516
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
468 517
         }
469 518
 
470 519
         // Check Scope attribute
471 520
         $actor = $fallbackActor ?? $this;
472
-        if ($this->options->checkScope) { # todo
521
+        if ($this->options->checkScope)
522
+        {
523
+# todo
473 524
             $ar = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null);
474
-            if ($ar !== null) {
525
+            if ($ar !== null)
526
+            {
475 527
                 /** @var Attribute\Scope $attr */
476 528
                 $attr = $ar->newInstance();
477 529
                 $scope = $this->scope;
478 530
                 $actor = $this;
479 531
                 // Go through all parent scopes
480 532
                 $needed = $actor;
481
-                while ($attr->name !== $scope->getScopeName()) {
533
+                while ($attr->name !== $scope->getScopeName())
534
+                {
482 535
                     $needed = $scope->getParentActor();
483
-                    if ($needed === null) {
536
+                    if ($needed === null)
537
+                    {
484 538
                         throw new BadScopeException($attr->name, $class);
485 539
                     }
486 540
 
@@ -493,11 +547,13 @@  discard block
 block discarded – undo
493 547
         } # todo
494 548
 
495 549
         // We have to construct class using external injector when we know the exact context
496
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
550
+        if ($arguments === [] && $this->binder->hasInjector($class))
551
+        {
497 552
             return $actor->resolveInjector($actor->state->bindings[$ctx->class], $ctx, $arguments, $tracer);
498 553
         }
499 554
 
500
-        if (!$reflection->isInstantiable()) {
555
+        if (!$reflection->isInstantiable())
556
+        {
501 557
             $itIs = match (true) {
502 558
                 $reflection->isEnum() => 'Enum',
503 559
                 $reflection->isAbstract() => 'Abstract class',
@@ -511,8 +567,10 @@  discard block
 block discarded – undo
511 567
 
512 568
         $constructor = $reflection->getConstructor();
513 569
 
514
-        if ($constructor !== null) {
515
-            try {
570
+        if ($constructor !== null)
571
+        {
572
+            try
573
+            {
516 574
                 $newScope = $this !== $actor;
517 575
                 $debug = [
518 576
                     'action' => 'resolve arguments',
@@ -526,39 +584,54 @@  discard block
 block discarded – undo
526 584
                 $tracer->push($newScope, ...$debug);
527 585
                 $tracer->push(true);
528 586
                 $args = $actor->resolver->resolveArguments($constructor, $arguments, $actor->options->validateArguments);
529
-            } catch (ValidationException $e) {
587
+            }
588
+            catch (ValidationException $e)
589
+            {
530 590
                 throw TracedContainerException::createWithTrace(\sprintf(
531 591
                     'Can\'t resolve `%s`. %s',
532 592
                     $tracer->getRootAlias(),
533 593
                     $e->getMessage(),
534 594
                 ), $tracer->getTraces());
535
-            } catch (TracedContainerException $e) {
595
+            }
596
+            catch (TracedContainerException $e)
597
+            {
536 598
                 throw $e::extendTracedException(\sprintf(
537 599
                     'Can\'t resolve `%s`.',
538 600
                     $tracer->getRootAlias(),
539 601
                 ), $tracer->getTraces(), $e);
540
-            } finally {
602
+            }
603
+            finally
604
+            {
541 605
                 $tracer->pop($newScope);
542 606
                 $tracer->pop(false);
543 607
             }
544
-            try {
608
+            try
609
+            {
545 610
                 // Using constructor with resolved arguments
546 611
                 $tracer->push(false, call: "$class::__construct", arguments: $args);
547 612
                 $tracer->push(true);
548 613
                 $instance = new $class(...$args);
549
-            } catch (\TypeError $e) {
614
+            }
615
+            catch (\TypeError $e)
616
+            {
550 617
                 throw new WrongTypeException($constructor, $e);
551
-            } catch (TracedContainerException $e) {
618
+            }
619
+            catch (TracedContainerException $e)
620
+            {
552 621
                 throw $e::extendTracedException(\sprintf(
553 622
                     'Can\'t resolve `%s`: failed constructing `%s`.',
554 623
                     $tracer->getRootAlias(),
555 624
                     $class,
556 625
                 ), $tracer->getTraces(), $e);
557
-            } finally {
626
+            }
627
+            finally
628
+            {
558 629
                 $tracer->pop(true);
559 630
                 $tracer->pop(false);
560 631
             }
561
-        } else {
632
+        }
633
+        else
634
+        {
562 635
             // No constructor specified
563 636
             $instance = $reflection->newInstance();
564 637
         }
@@ -590,12 +663,14 @@  discard block
 block discarded – undo
590 663
      */
591 664
     private function isSingleton(Ctx $ctx): bool
592 665
     {
593
-        if (is_bool($ctx->singleton)) {
666
+        if (is_bool($ctx->singleton))
667
+        {
594 668
             return $ctx->singleton;
595 669
         }
596 670
 
597 671
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
598
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
672
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class))
673
+        {
599 674
             return true;
600 675
         }
601 676
 
@@ -609,7 +684,8 @@  discard block
 block discarded – undo
609 684
          * @var Attribute\Finalize|null $attribute
610 685
          */
611 686
         $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance();
612
-        if ($attribute === null) {
687
+        if ($attribute === null)
688
+        {
613 689
             return null;
614 690
         }
615 691
 
@@ -623,10 +699,14 @@  discard block
 block discarded – undo
623 699
     {
624 700
         $scope = $this->scope;
625 701
 
626
-        while ($scope !== null) {
627
-            foreach ($this->state->inflectors as $class => $inflectors) {
628
-                if ($instance instanceof $class) {
629
-                    foreach ($inflectors as $inflector) {
702
+        while ($scope !== null)
703
+        {
704
+            foreach ($this->state->inflectors as $class => $inflectors)
705
+            {
706
+                if ($instance instanceof $class)
707
+                {
708
+                    foreach ($inflectors as $inflector)
709
+                    {
630 710
                         $instance = $inflector->getParametersCount() > 1
631 711
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
632 712
                             : ($inflector->inflector)($instance);
@@ -642,9 +722,12 @@  discard block
 block discarded – undo
642 722
 
643 723
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
644 724
     {
645
-        try {
725
+        try
726
+        {
646 727
             $this->resolver->validateArguments($reflection, $arguments);
647
-        } catch (\Throwable) {
728
+        }
729
+        catch (\Throwable)
730
+        {
648 731
             return false;
649 732
         }
650 733
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Tracer.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,19 +34,19 @@  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
             $this->traces[] = $trace === null ? [] : [$trace];
39
-        } elseif ($trace !== null) {
39
+        } elseif ($trace !== null){
40 40
             $this->traces[\array_key_last($this->traces)][] = $trace;
41 41
         }
42 42
     }
43 43
 
44 44
     public function pop(bool $previousLevel = false): void
45 45
     {
46
-        if ($this->traces === []) {
46
+        if ($this->traces === []){
47 47
             return;
48 48
         }
49
-        if ($previousLevel) {
49
+        if ($previousLevel){
50 50
             \array_pop($this->traces);
51 51
             return;
52 52
         }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     public function __toString(): string
64 64
     {
65
-        return $this->traces === [] ? '' : "Resolving trace:\n" . self::renderTraceList($this->traces);
65
+        return $this->traces === [] ? '' : "Resolving trace:\n".self::renderTraceList($this->traces);
66 66
     }
67 67
 
68 68
     /**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $result = [];
74 74
         $i = 0;
75
-        foreach ($blocks as $block) {
75
+        foreach ($blocks as $block){
76 76
             \array_push($result, ...self::blockToStringList($block, $i++));
77 77
         }
78 78
         return \implode("\n", $result);
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
         // Separator
93 93
         $s = "\n";
94 94
         $nexPrefix = "$s$padding  ";
95
-        foreach ($items as $item) {
96
-            $result[] = $firstPrefix . \str_replace($s, $nexPrefix, (string) $item);
95
+        foreach ($items as $item){
96
+            $result[] = $firstPrefix.\str_replace($s, $nexPrefix, (string)$item);
97 97
         }
98 98
         return $result;
99 99
     }
Please login to merge, or discard this 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.