Passed
Push — master ( 2fcc18...44459b )
by butschster
11:39 queued 15s
created
src/Core/tests/InjectableTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 
40 40
     public function testInvalidInjector(): void
41 41
     {
42
-        $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " .
42
+        $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ".
43 43
                     "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'";
44 44
         $this->expectException(InjectionException::class);
45 45
         $this->expectExceptionMessage($excepted);
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 
66 66
     public function testInvalidRuntimeInjector(): void
67 67
     {
68
-        $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " .
68
+        $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ".
69 69
             "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'";
70 70
         $this->expectException(InjectionException::class);
71 71
         $this->expectExceptionMessage($excepted);
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         $container->bind(ConfigsInterface::class, $configurator);
103 103
 
104 104
         $configurator->shouldReceive('createInjection')
105
-            ->with(m::on(static function (ReflectionClass $r) {
105
+            ->with(m::on(static function (ReflectionClass $r){
106 106
                 return $r->getName() === TestConfig::class;
107 107
             }), null)
108 108
             ->andReturn($expected);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         $container->bind(ConfigsInterface::class, $configurator);
120 120
 
121 121
         $configurator->shouldReceive('createInjection')
122
-            ->with(m::on(static function (ReflectionClass $r) {
122
+            ->with(m::on(static function (ReflectionClass $r){
123 123
                 return $r->getName() === TestConfig::class;
124 124
             }), 'context')
125 125
             ->andReturn($expected);
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
     public function testExtendedInjectorAnonClassObjectParam(): void
208 208
     {
209 209
         $container = new Container();
210
-        $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface {
211
-            public function createInjection(\ReflectionClass $class, object|string|null $context = null): object
210
+        $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface{
211
+            public function createInjection(\ReflectionClass $class, object | string | null $context = null): object
212 212
             {
213 213
                 return (object)['context' => $context];
214 214
             }
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
     public function testExtendedInjectorAnonClassMixedParam(): void
224 224
     {
225 225
         $container = new Container();
226
-        $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface {
226
+        $container->bind(stdClass::class, new Injectable(new class implements Container\InjectorInterface{
227 227
             public function createInjection(\ReflectionClass $class, mixed $context = null): object
228 228
             {
229 229
                 return (object)['context' => $context];
Please login to merge, or discard this patch.
src/Core/tests/Fixtures/ExtendedContextInjector.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
  */
13 13
 class ExtendedContextInjector implements InjectorInterface
14 14
 {
15
-    public function createInjection(\ReflectionClass $class, \ReflectionParameter|string|null $context = null): object
15
+    public function createInjection(\ReflectionClass $class, \ReflectionParameter | string | null $context = null): object
16 16
     {
17 17
         return (object)['context' => $context];
18 18
     }
Please login to merge, or discard this patch.
src/Core/src/Internal/Container.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     use DestructorTrait;
20 20
 
21 21
     private State $state;
22
-    private FactoryInterface|Factory $factory;
22
+    private FactoryInterface | Factory $factory;
23 23
 
24 24
     public function __construct(Registry $constructor)
25 25
     {
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @throws ContainerException
48 48
      * @throws \Throwable
49 49
      */
50
-    public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
50
+    public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed
51 51
     {
52
-        if ($id instanceof Autowire) {
52
+        if ($id instanceof Autowire){
53 53
             return $id->resolve($this->factory);
54 54
         }
55 55
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,8 @@
 block discarded – undo
49 49
      */
50 50
     public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed
51 51
     {
52
-        if ($id instanceof Autowire) {
52
+        if ($id instanceof Autowire)
53
+        {
53 54
             return $id->resolve($this->factory);
54 55
         }
55 56
 
Please login to merge, or discard this patch.
src/Core/src/Internal/Resolver.php 2 patches
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     ): array {
53 53
         $state = new ResolvingState($reflection, $parameters);
54 54
 
55
-        foreach ($reflection->getParameters() as $parameter) {
55
+        foreach ($reflection->getParameters() as $parameter){
56 56
             $this->resolveParameter($parameter, $state, $validate)
57 57
             or
58 58
             throw new ArgumentResolvingException($reflection, $parameter->getName());
@@ -66,47 +66,47 @@  discard block
 block discarded – undo
66 66
         $positional = true;
67 67
         $variadic = false;
68 68
         $parameters = $reflection->getParameters();
69
-        if (\count($parameters) === 0) {
69
+        if (\count($parameters) === 0){
70 70
             return;
71 71
         }
72 72
 
73 73
         $parameter = null;
74
-        while (\count($parameters) > 0 || \count($arguments) > 0) {
74
+        while (\count($parameters) > 0 || \count($arguments) > 0){
75 75
             // get related argument value
76 76
             $key = \key($arguments);
77 77
 
78 78
             // For a variadic parameter it's no sense - named or positional argument will be sent
79 79
             // But you can't send positional argument after named in any case
80
-            if (\is_int($key) && !$positional) {
80
+            if (\is_int($key) && !$positional){
81 81
                 throw new PositionalArgumentException($reflection, $key);
82 82
             }
83 83
 
84 84
             $positional = $positional && \is_int($key);
85 85
 
86
-            if (!$variadic) {
86
+            if (!$variadic){
87 87
                 $parameter = \array_shift($parameters);
88 88
                 $variadic = $parameter?->isVariadic() ?? false;
89 89
             }
90 90
 
91
-            if ($parameter === null) {
91
+            if ($parameter === null){
92 92
                 throw new UnknownParameterException($reflection, $key);
93 93
             }
94 94
             $name = $parameter->getName();
95 95
 
96
-            if (($positional || $variadic) && $key !== null) {
96
+            if (($positional || $variadic) && $key !== null){
97 97
                 /** @psalm-suppress ReferenceReusedFromConfusingScope */
98 98
                 $value = \array_shift($arguments);
99
-            } elseif ($key === null || !\array_key_exists($name, $arguments)) {
100
-                if ($parameter->isOptional()) {
99
+            } elseif ($key === null || !\array_key_exists($name, $arguments)){
100
+                if ($parameter->isOptional()){
101 101
                     continue;
102 102
                 }
103 103
                 throw new MissingRequiredArgumentException($reflection, $name);
104
-            } else {
104
+            }else{
105 105
                 $value = &$arguments[$name];
106 106
                 unset($arguments[$name]);
107 107
             }
108 108
 
109
-            if (!$this->validateValueToParameter($parameter, $value)) {
109
+            if (!$this->validateValueToParameter($parameter, $value)){
110 110
                 throw new InvalidArgumentException($reflection, $name);
111 111
             }
112 112
         }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 
115 115
     private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool
116 116
     {
117
-        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) {
117
+        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){
118 118
             return true;
119 119
         }
120 120
         $type = $parameter->getType();
@@ -125,17 +125,17 @@  discard block
 block discarded – undo
125 125
             $type instanceof ReflectionIntersectionType => [false, $type->getTypes()],
126 126
         };
127 127
 
128
-        foreach ($types as $t) {
128
+        foreach ($types as $t){
129 129
             \assert($t instanceof ReflectionNamedType);
130
-            if (!$this->validateValueNamedType($t, $value)) {
130
+            if (!$this->validateValueNamedType($t, $value)){
131 131
                 // If it is TypeIntersection
132
-                if ($or) {
132
+                if ($or){
133 133
                     continue;
134 134
                 }
135 135
                 return false;
136 136
             }
137 137
             // If it is not type intersection then we can skip that value after first successful check
138
-            if ($or) {
138
+            if ($or){
139 139
                 return true;
140 140
             }
141 141
         }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     {
151 151
         $name = $type->getName();
152 152
 
153
-        if ($type->isBuiltin()) {
153
+        if ($type->isBuiltin()){
154 154
             return match ($name) {
155 155
                 'mixed' => true,
156 156
                 'string' => \is_string($value),
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 
184 184
         // Try to resolve parameter by name
185 185
         $res = $state->resolveParameterByNameOrPosition($parameter, $isVariadic);
186
-        if ($res !== [] || $isVariadic) {
186
+        if ($res !== [] || $isVariadic){
187 187
             // validate
188
-            if ($isVariadic) {
189
-                foreach ($res as $k => &$v) {
190
-                    $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key: $k);
188
+            if ($isVariadic){
189
+                foreach ($res as $k => &$v){
190
+                    $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key : $k);
191 191
                 }
192
-            } else {
192
+            }else{
193 193
                 $this->processArgument($state, $res[0], validateWith: $validate ? $parameter : null);
194 194
             }
195 195
 
@@ -197,39 +197,39 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         $error = null;
200
-        if ($hasType) {
200
+        if ($hasType){
201 201
             /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $reflectionType */
202 202
             $reflectionType = $parameter->getType();
203 203
 
204
-            if ($reflectionType instanceof ReflectionIntersectionType) {
204
+            if ($reflectionType instanceof ReflectionIntersectionType){
205 205
                 throw new UnsupportedTypeException($parameter->getDeclaringFunction(), $parameter->getName());
206 206
             }
207 207
 
208 208
             $types = $reflectionType instanceof ReflectionNamedType ? [$reflectionType] : $reflectionType->getTypes();
209
-            foreach ($types as $namedType) {
210
-                try {
211
-                    if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $parameter, $validate)) {
209
+            foreach ($types as $namedType){
210
+                try{
211
+                    if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $parameter, $validate)){
212 212
                         return true;
213 213
                     }
214
-                } catch (Throwable $e) {
214
+                }catch (Throwable $e){
215 215
                     $error = $e;
216 216
                 }
217 217
             }
218 218
         }
219 219
 
220
-        if ($parameter->isDefaultValueAvailable()) {
220
+        if ($parameter->isDefaultValueAvailable()){
221 221
             $argument = $parameter->getDefaultValue();
222 222
             $this->processArgument($state, $argument);
223 223
             return true;
224 224
         }
225 225
 
226
-        if ($hasType && $parameter->allowsNull()) {
226
+        if ($hasType && $parameter->allowsNull()){
227 227
             $argument = null;
228 228
             $this->processArgument($state, $argument);
229 229
             return true;
230 230
         }
231 231
 
232
-        if ($error === null) {
232
+        if ($error === null){
233 233
             return false;
234 234
         }
235 235
 
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
         ResolvingState $state,
268 268
         mixed &$value,
269 269
         ReflectionParameter $validateWith = null,
270
-        int|string $key = null
270
+        int | string $key = null
271 271
     ): void {
272 272
         // Resolve Autowire objects
273
-        if ($value instanceof Autowire) {
273
+        if ($value instanceof Autowire){
274 274
             $value = $value->resolve($this->factory);
275 275
         }
276 276
 
277 277
         // Validation
278
-        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) {
278
+        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){
279 279
             throw new InvalidArgumentException(
280 280
                 $validateWith->getDeclaringFunction(),
281 281
                 $validateWith->getName()
Please login to merge, or discard this patch.
Braces   +68 added lines, -32 removed lines patch added patch discarded remove patch
@@ -52,7 +52,8 @@  discard block
 block discarded – undo
52 52
     ): array {
53 53
         $state = new ResolvingState($reflection, $parameters);
54 54
 
55
-        foreach ($reflection->getParameters() as $parameter) {
55
+        foreach ($reflection->getParameters() as $parameter)
56
+        {
56 57
             $this->resolveParameter($parameter, $state, $validate)
57 58
             or
58 59
             throw new ArgumentResolvingException($reflection, $parameter->getName());
@@ -66,47 +67,59 @@  discard block
 block discarded – undo
66 67
         $positional = true;
67 68
         $variadic = false;
68 69
         $parameters = $reflection->getParameters();
69
-        if (\count($parameters) === 0) {
70
+        if (\count($parameters) === 0)
71
+        {
70 72
             return;
71 73
         }
72 74
 
73 75
         $parameter = null;
74
-        while (\count($parameters) > 0 || \count($arguments) > 0) {
76
+        while (\count($parameters) > 0 || \count($arguments) > 0)
77
+        {
75 78
             // get related argument value
76 79
             $key = \key($arguments);
77 80
 
78 81
             // For a variadic parameter it's no sense - named or positional argument will be sent
79 82
             // But you can't send positional argument after named in any case
80
-            if (\is_int($key) && !$positional) {
83
+            if (\is_int($key) && !$positional)
84
+            {
81 85
                 throw new PositionalArgumentException($reflection, $key);
82 86
             }
83 87
 
84 88
             $positional = $positional && \is_int($key);
85 89
 
86
-            if (!$variadic) {
90
+            if (!$variadic)
91
+            {
87 92
                 $parameter = \array_shift($parameters);
88 93
                 $variadic = $parameter?->isVariadic() ?? false;
89 94
             }
90 95
 
91
-            if ($parameter === null) {
96
+            if ($parameter === null)
97
+            {
92 98
                 throw new UnknownParameterException($reflection, $key);
93 99
             }
94 100
             $name = $parameter->getName();
95 101
 
96
-            if (($positional || $variadic) && $key !== null) {
102
+            if (($positional || $variadic) && $key !== null)
103
+            {
97 104
                 /** @psalm-suppress ReferenceReusedFromConfusingScope */
98 105
                 $value = \array_shift($arguments);
99
-            } elseif ($key === null || !\array_key_exists($name, $arguments)) {
100
-                if ($parameter->isOptional()) {
106
+            }
107
+            elseif ($key === null || !\array_key_exists($name, $arguments))
108
+            {
109
+                if ($parameter->isOptional())
110
+                {
101 111
                     continue;
102 112
                 }
103 113
                 throw new MissingRequiredArgumentException($reflection, $name);
104
-            } else {
114
+            }
115
+            else
116
+            {
105 117
                 $value = &$arguments[$name];
106 118
                 unset($arguments[$name]);
107 119
             }
108 120
 
109
-            if (!$this->validateValueToParameter($parameter, $value)) {
121
+            if (!$this->validateValueToParameter($parameter, $value))
122
+            {
110 123
                 throw new InvalidArgumentException($reflection, $name);
111 124
             }
112 125
         }
@@ -114,7 +127,8 @@  discard block
 block discarded – undo
114 127
 
115 128
     private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool
116 129
     {
117
-        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) {
130
+        if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null))
131
+        {
118 132
             return true;
119 133
         }
120 134
         $type = $parameter->getType();
@@ -125,17 +139,21 @@  discard block
 block discarded – undo
125 139
             $type instanceof ReflectionIntersectionType => [false, $type->getTypes()],
126 140
         };
127 141
 
128
-        foreach ($types as $t) {
142
+        foreach ($types as $t)
143
+        {
129 144
             \assert($t instanceof ReflectionNamedType);
130
-            if (!$this->validateValueNamedType($t, $value)) {
145
+            if (!$this->validateValueNamedType($t, $value))
146
+            {
131 147
                 // If it is TypeIntersection
132
-                if ($or) {
148
+                if ($or)
149
+                {
133 150
                     continue;
134 151
                 }
135 152
                 return false;
136 153
             }
137 154
             // If it is not type intersection then we can skip that value after first successful check
138
-            if ($or) {
155
+            if ($or)
156
+            {
139 157
                 return true;
140 158
             }
141 159
         }
@@ -150,7 +168,8 @@  discard block
 block discarded – undo
150 168
     {
151 169
         $name = $type->getName();
152 170
 
153
-        if ($type->isBuiltin()) {
171
+        if ($type->isBuiltin())
172
+        {
154 173
             return match ($name) {
155 174
                 'mixed' => true,
156 175
                 'string' => \is_string($value),
@@ -183,13 +202,18 @@  discard block
 block discarded – undo
183 202
 
184 203
         // Try to resolve parameter by name
185 204
         $res = $state->resolveParameterByNameOrPosition($parameter, $isVariadic);
186
-        if ($res !== [] || $isVariadic) {
205
+        if ($res !== [] || $isVariadic)
206
+        {
187 207
             // validate
188
-            if ($isVariadic) {
189
-                foreach ($res as $k => &$v) {
208
+            if ($isVariadic)
209
+            {
210
+                foreach ($res as $k => &$v)
211
+                {
190 212
                     $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key: $k);
191 213
                 }
192
-            } else {
214
+            }
215
+            else
216
+            {
193 217
                 $this->processArgument($state, $res[0], validateWith: $validate ? $parameter : null);
194 218
             }
195 219
 
@@ -197,39 +221,49 @@  discard block
 block discarded – undo
197 221
         }
198 222
 
199 223
         $error = null;
200
-        if ($hasType) {
224
+        if ($hasType)
225
+        {
201 226
             /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $reflectionType */
202 227
             $reflectionType = $parameter->getType();
203 228
 
204
-            if ($reflectionType instanceof ReflectionIntersectionType) {
229
+            if ($reflectionType instanceof ReflectionIntersectionType)
230
+            {
205 231
                 throw new UnsupportedTypeException($parameter->getDeclaringFunction(), $parameter->getName());
206 232
             }
207 233
 
208 234
             $types = $reflectionType instanceof ReflectionNamedType ? [$reflectionType] : $reflectionType->getTypes();
209
-            foreach ($types as $namedType) {
210
-                try {
211
-                    if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $parameter, $validate)) {
235
+            foreach ($types as $namedType)
236
+            {
237
+                try
238
+                {
239
+                    if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $parameter, $validate))
240
+                    {
212 241
                         return true;
213 242
                     }
214
-                } catch (Throwable $e) {
243
+                }
244
+                catch (Throwable $e)
245
+                {
215 246
                     $error = $e;
216 247
                 }
217 248
             }
218 249
         }
219 250
 
220
-        if ($parameter->isDefaultValueAvailable()) {
251
+        if ($parameter->isDefaultValueAvailable())
252
+        {
221 253
             $argument = $parameter->getDefaultValue();
222 254
             $this->processArgument($state, $argument);
223 255
             return true;
224 256
         }
225 257
 
226
-        if ($hasType && $parameter->allowsNull()) {
258
+        if ($hasType && $parameter->allowsNull())
259
+        {
227 260
             $argument = null;
228 261
             $this->processArgument($state, $argument);
229 262
             return true;
230 263
         }
231 264
 
232
-        if ($error === null) {
265
+        if ($error === null)
266
+        {
233 267
             return false;
234 268
         }
235 269
 
@@ -270,12 +304,14 @@  discard block
 block discarded – undo
270 304
         int|string $key = null
271 305
     ): void {
272 306
         // Resolve Autowire objects
273
-        if ($value instanceof Autowire) {
307
+        if ($value instanceof Autowire)
308
+        {
274 309
             $value = $value->resolve($this->factory);
275 310
         }
276 311
 
277 312
         // Validation
278
-        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) {
313
+        if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value))
314
+        {
279 315
             throw new InvalidArgumentException(
280 316
                 $validateWith->getDeclaringFunction(),
281 317
                 $validateWith->getName()
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory/Ctx.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
17 17
     public function __construct(
18 18
         public readonly string $alias,
19 19
         public string $class,
20
-        public \Stringable|string|null $context = null,
20
+        public \Stringable | string | null $context = null,
21 21
         public ?bool $singleton = null,
22 22
         public ?\ReflectionClass $reflection = null,
23
-    ) {
23
+    ){
24 24
     }
25 25
 }
Please login to merge, or discard this patch.
src/Core/src/Container.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
     public const DEFAULT_ROOT_SCOPE_NAME = 'root';
50 50
 
51 51
     private Internal\State $state;
52
-    private ResolverInterface|Internal\Resolver $resolver;
53
-    private FactoryInterface|Internal\Factory $factory;
54
-    private ContainerInterface|Internal\Container $container;
55
-    private BinderInterface|Internal\Binder $binder;
56
-    private InvokerInterface|Internal\Invoker $invoker;
52
+    private ResolverInterface | Internal\Resolver $resolver;
53
+    private FactoryInterface | Internal\Factory $factory;
54
+    private ContainerInterface | Internal\Container $container;
55
+    private BinderInterface | Internal\Binder $binder;
56
+    private InvokerInterface | Internal\Invoker $invoker;
57 57
     private Internal\Scope $scope;
58 58
 
59 59
     /**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     public function __construct(
63 63
         private Config $config = new Config(),
64 64
         ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME,
65
-    ) {
65
+    ){
66 66
         $this->initServices($this, $scopeName);
67 67
 
68 68
         /** @psalm-suppress RedundantPropertyInitializationCheck */
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @throws ContainerException
115 115
      * @throws \Throwable
116 116
      */
117
-    public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed
117
+    public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed
118 118
     {
119 119
         /** @psalm-suppress TooManyArguments */
120 120
         return $this->factory->make($alias, $parameters, $context);
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      * @throws ContainerException
139 139
      * @throws \Throwable
140 140
      */
141
-    public function get(string|Autowire $id, string $context = null): mixed
141
+    public function get(string | Autowire $id, string $context = null): mixed
142 142
     {
143 143
         /** @psalm-suppress TooManyArguments */
144 144
         return $this->container->get($id, $context);
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
         $binds = &$this->state->bindings;
165 165
         $singletons = &$this->state->singletons;
166 166
         $cleanup = $previous = $prevSin = [];
167
-        foreach ($bindings as $alias => $resolver) {
167
+        foreach ($bindings as $alias => $resolver){
168 168
             // Store previous bindings
169
-            if (isset($binds[$alias])) {
169
+            if (isset($binds[$alias])){
170 170
                 $previous[$alias] = $binds[$alias];
171
-            } else {
171
+            }else{
172 172
                 // Store bindings to be removed
173 173
                 $cleanup[] = $alias;
174 174
             }
175 175
             // Store previous singletons
176
-            if (isset($singletons[$alias])) {
176
+            if (isset($singletons[$alias])){
177 177
                 $prevSin[$alias] = $singletons[$alias];
178 178
                 unset($singletons[$alias]);
179 179
             }
@@ -181,21 +181,21 @@  discard block
 block discarded – undo
181 181
             $this->binder->bind($alias, $resolver);
182 182
         }
183 183
 
184
-        try {
184
+        try{
185 185
             return ContainerScope::getContainer() !== $this
186 186
                 ? ContainerScope::runScope($this, $scope)
187 187
                 : $scope($this);
188
-        } finally {
188
+        }finally{
189 189
             // Remove new bindings
190
-            foreach ($cleanup as $alias) {
190
+            foreach ($cleanup as $alias){
191 191
                 unset($binds[$alias], $singletons[$alias]);
192 192
             }
193 193
             // Restore previous bindings
194
-            foreach ($previous as $alias => $resolver) {
194
+            foreach ($previous as $alias => $resolver){
195 195
                 $binds[$alias] = $resolver;
196 196
             }
197 197
             // Restore singletons
198
-            foreach ($prevSin as $alias => $instance) {
198
+            foreach ($prevSin as $alias => $instance){
199 199
                 $singletons[$alias] = $instance;
200 200
             }
201 201
         }
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
         $container->scope->setParent($this, $this->scope);
214 214
 
215 215
         // Add specific bindings
216
-        foreach ($bindings as $alias => $resolver) {
216
+        foreach ($bindings as $alias => $resolver){
217 217
             $container->binder->bind($alias, $resolver);
218 218
         }
219 219
 
220 220
         return ContainerScope::runScope(
221 221
             $container,
222 222
             static function (self $container) use ($autowire, $closure): mixed {
223
-                try {
223
+                try{
224 224
                     return $autowire
225 225
                         ? $container->invoke($closure)
226 226
                         : $closure($container);
227
-                } finally {
227
+                }finally{
228 228
                     $container->closeScope();
229 229
                 }
230 230
             }
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
      * @param bool $force If the value is false, an exception will be thrown when attempting
260 260
      *  to bind an already constructed singleton.
261 261
      */
262
-    public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void
262
+    public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void
263 263
     {
264
-        if ($force) {
264
+        if ($force){
265 265
             $this->binder->removeBinding($alias);
266 266
         }
267 267
 
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
         ]);
331 331
 
332 332
         // Create container services
333
-        foreach ($container->config as $property => $class) {
334
-            if (\property_exists($container, $property)) {
333
+        foreach ($container->config as $property => $class){
334
+            if (\property_exists($container, $property)){
335 335
                 $container->$property = $constructor->get($property, $class);
336 336
             }
337 337
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
     private function closeScope(): void
346 346
     {
347 347
         /** @psalm-suppress RedundantPropertyInitializationCheck */
348
-        if (!isset($this->scope)) {
348
+        if (!isset($this->scope)){
349 349
             $this->destruct();
350 350
             return;
351 351
         }
@@ -354,10 +354,10 @@  discard block
 block discarded – undo
354 354
 
355 355
         // Run finalizers
356 356
         $errors = [];
357
-        foreach ($this->state->finalizers as $finalizer) {
358
-            try {
357
+        foreach ($this->state->finalizers as $finalizer){
358
+            try{
359 359
                 $this->invoker->invoke($finalizer);
360
-            } catch (\Throwable $e) {
360
+            }catch (\Throwable $e){
361 361
                 $errors[] = $e;
362 362
             }
363 363
         }
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
         $this->destruct();
367 367
 
368 368
         // Throw collected errors
369
-        if ($errors !== []) {
369
+        if ($errors !== []){
370 370
             throw new FinalizersException($scopeName, $errors);
371 371
         }
372 372
     }
Please login to merge, or discard this patch.
src/Core/src/Internal/Factory.php 2 patches
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @throws \Throwable
68 68
      */
69
-    public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed
69
+    public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed
70 70
     {
71
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
71
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){
72 72
             return $this->state->singletons[$alias];
73 73
         }
74 74
 
75 75
         $binding = $this->state->bindings[$alias] ?? null;
76 76
 
77
-        if ($binding === null) {
77
+        if ($binding === null){
78 78
             return $this->resolveWithoutBinding($alias, $parameters, $context);
79 79
         }
80 80
 
81
-        try {
81
+        try{
82 82
             $this->tracer->push(
83 83
                 false,
84 84
                 action: 'resolve from binding',
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                     ->resolveWeakReference($binding, $alias, $context, $parameters),
107 107
                 default => $binding,
108 108
             };
109
-        } finally {
109
+        }finally{
110 110
             $this->state->bindings[$alias] ??= $binding;
111 111
             $this->tracer->pop(true);
112 112
             $this->tracer->pop(false);
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
     private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments)
121 121
     {
122 122
         $context = $ctx->context;
123
-        try {
123
+        try{
124 124
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
125
-        } catch (\ReflectionException $e) {
125
+        }catch (\ReflectionException $e){
126 126
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
127 127
         }
128 128
 
129 129
         $injector = $binding->injector;
130 130
 
131
-        try {
131
+        try{
132 132
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
133 133
 
134
-            if (!$injectorInstance instanceof InjectorInterface) {
134
+            if (!$injectorInstance instanceof InjectorInterface){
135 135
                 throw new InjectionException(
136 136
                     \sprintf(
137 137
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
                 default => (string)$context,
159 159
             });
160 160
 
161
-            if (!$reflection->isInstance($instance)) {
161
+            if (!$reflection->isInstance($instance)){
162 162
                 throw new InjectionException(
163 163
                     \sprintf(
164 164
                         "Invalid injection response for '%s'.",
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             }
169 169
 
170 170
             return $instance;
171
-        } finally {
171
+        }finally{
172 172
             $this->state->bindings[$ctx->class] ??= $binding;
173 173
         }
174 174
     }
@@ -176,18 +176,18 @@  discard block
 block discarded – undo
176 176
     private function resolveAlias(
177 177
         \Spiral\Core\Config\Alias $binding,
178 178
         string $alias,
179
-        Stringable|string|null $context,
179
+        Stringable | string | null $context,
180 180
         array $arguments,
181 181
     ): mixed {
182 182
         $result = $binding->alias === $alias
183 183
             ? $this->autowire(
184
-                new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton),
184
+                new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton),
185 185
                 $arguments,
186 186
             )
187 187
             //Binding is pointing to something else
188 188
             : $this->make($binding->alias, $arguments, $context);
189 189
 
190
-        if ($binding->singleton && $arguments === []) {
190
+        if ($binding->singleton && $arguments === []){
191 191
             $this->state->singletons[$alias] = $result;
192 192
         }
193 193
 
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
     private function resolveShared(
198 198
         \Spiral\Core\Config\Shared $binding,
199 199
         string $alias,
200
-        Stringable|string|null $context,
200
+        Stringable | string | null $context,
201 201
         array $arguments,
202 202
     ): object {
203 203
         $avoidCache = $arguments !== [];
204 204
         return $avoidCache
205 205
             ? $this->createInstance(
206
-                new Ctx(alias: $alias, class: $binding->value::class, context: $context),
206
+                new Ctx(alias : $alias, class : $binding->value::class, context : $context),
207 207
                 $arguments,
208 208
             )
209 209
             : $binding->value;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     private function resolveAutowire(
213 213
         \Spiral\Core\Config\Autowire $binding,
214 214
         string $alias,
215
-        Stringable|string|null $context,
215
+        Stringable | string | null $context,
216 216
         array $arguments,
217 217
     ): mixed {
218 218
         $instance = $binding->autowire->resolve($this, $arguments);
@@ -222,17 +222,17 @@  discard block
 block discarded – undo
222 222
     }
223 223
 
224 224
     private function resolveFactory(
225
-        \Spiral\Core\Config\Factory|DeferredFactory $binding,
225
+        \Spiral\Core\Config\Factory | DeferredFactory $binding,
226 226
         string $alias,
227
-        Stringable|string|null $context,
227
+        Stringable | string | null $context,
228 228
         array $arguments,
229 229
     ): mixed {
230 230
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
231
-        try {
231
+        try{
232 232
             $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0
233 233
                 ? ($binding->factory)()
234 234
                 : $this->invoker->invoke($binding->factory, $arguments);
235
-        } catch (NotCallableException $e) {
235
+        }catch (NotCallableException $e){
236 236
             throw new ContainerException(
237 237
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
238 238
                 $e->getCode(),
@@ -246,24 +246,24 @@  discard block
 block discarded – undo
246 246
     private function resolveWeakReference(
247 247
         \Spiral\Core\Config\WeakReference $binding,
248 248
         string $alias,
249
-        Stringable|string|null $context,
249
+        Stringable | string | null $context,
250 250
         array $arguments,
251 251
     ): ?object {
252 252
         $avoidCache = $arguments !== [];
253 253
 
254
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
255
-            try {
254
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){
255
+            try{
256 256
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
257 257
 
258 258
                 $object = $this->createInstance(
259 259
                     new Ctx(alias: $alias, class: $alias, context: $context),
260 260
                     $arguments,
261 261
                 );
262
-                if ($avoidCache) {
262
+                if ($avoidCache){
263 263
                     return $object;
264 264
                 }
265 265
                 $binding->reference = WeakReference::create($object);
266
-            } catch (\Throwable) {
266
+            }catch (\Throwable){
267 267
                 throw new ContainerException(
268 268
                     $this->tracer->combineTraceMessage(
269 269
                         \sprintf(
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
                         )
274 274
                     )
275 275
                 );
276
-            } finally {
276
+            }finally{
277 277
                 $this->tracer->pop();
278 278
             }
279 279
         }
@@ -284,22 +284,22 @@  discard block
 block discarded – undo
284 284
     private function resolveWithoutBinding(
285 285
         string $alias,
286 286
         array $parameters = [],
287
-        Stringable|string|null $context = null
287
+        Stringable | string | null $context = null
288 288
     ): mixed {
289 289
         $parent = $this->scope->getParent();
290 290
 
291
-        if ($parent !== null) {
292
-            try {
291
+        if ($parent !== null){
292
+            try{
293 293
                 $this->tracer->push(false, ...[
294 294
                     'current scope' => $this->scope->getScopeName(),
295 295
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
296 296
                 ]);
297 297
                 return $parent->make($alias, $parameters, $context);
298
-            } catch (BadScopeException $e) {
299
-                if ($this->scope->getScopeName() !== $e->getScope()) {
298
+            }catch (BadScopeException $e){
299
+                if ($this->scope->getScopeName() !== $e->getScope()){
300 300
                     throw $e;
301 301
                 }
302
-            } catch (ContainerExceptionInterface $e) {
302
+            }catch (ContainerExceptionInterface $e){
303 303
                 $className = match (true) {
304 304
                     $e instanceof NotFoundException => NotFoundException::class,
305 305
                     default => ContainerException::class,
@@ -308,19 +308,19 @@  discard block
 block discarded – undo
308 308
                     'Can\'t resolve `%s`.',
309 309
                     $alias,
310 310
                 )), previous: $e);
311
-            } finally {
311
+            }finally{
312 312
                 $this->tracer->pop(false);
313 313
             }
314 314
         }
315 315
 
316 316
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
317
-        try {
317
+        try{
318 318
             //No direct instructions how to construct class, make is automatically
319 319
             return $this->autowire(
320 320
                 new Ctx(alias: $alias, class: $alias, context: $context),
321 321
                 $parameters,
322 322
             );
323
-        } finally {
323
+        }finally{
324 324
             $this->tracer->pop(false);
325 325
         }
326 326
     }
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
                 &&
342 342
                 (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class))
343 343
         ))
344
-        ) {
344
+        ){
345 345
             throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf(
346 346
                 'Can\'t resolve `%s`: undefined class or binding `%s`.',
347 347
                 $this->tracer->getRootAlias(),
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
         // Check scope name
371 371
         $ctx->reflection = new \ReflectionClass($instance);
372 372
         $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name;
373
-        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) {
373
+        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){
374 374
             throw new BadScopeException($scopeName, $instance::class);
375 375
         }
376 376
 
@@ -397,24 +397,24 @@  discard block
 block discarded – undo
397 397
         array $arguments,
398 398
     ): object {
399 399
         $class = $ctx->class;
400
-        try {
400
+        try{
401 401
             $ctx->reflection = $reflection = new \ReflectionClass($class);
402
-        } catch (\ReflectionException $e) {
402
+        }catch (\ReflectionException $e){
403 403
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
404 404
         }
405 405
 
406 406
         // Check scope name
407 407
         $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name;
408
-        if ($scope !== null && $scope !== $this->scope->getScopeName()) {
408
+        if ($scope !== null && $scope !== $this->scope->getScopeName()){
409 409
             throw new BadScopeException($scope, $class);
410 410
         }
411 411
 
412 412
         // We have to construct class using external injector when we know the exact context
413
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
413
+        if ($arguments === [] && $this->binder->hasInjector($class)){
414 414
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
415 415
         }
416 416
 
417
-        if (!$reflection->isInstantiable()) {
417
+        if (!$reflection->isInstantiable()){
418 418
             $itIs = match (true) {
419 419
                 $reflection->isEnum() => 'Enum',
420 420
                 $reflection->isAbstract() => 'Abstract class',
@@ -427,12 +427,12 @@  discard block
 block discarded – undo
427 427
 
428 428
         $constructor = $reflection->getConstructor();
429 429
 
430
-        if ($constructor !== null) {
431
-            try {
430
+        if ($constructor !== null){
431
+            try{
432 432
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
433 433
                 $this->tracer->push(true);
434 434
                 $args = $this->resolver->resolveArguments($constructor, $arguments);
435
-            } catch (ValidationException $e) {
435
+            }catch (ValidationException $e){
436 436
                 throw new ContainerException(
437 437
                     $this->tracer->combineTraceMessage(
438 438
                         \sprintf(
@@ -442,22 +442,22 @@  discard block
 block discarded – undo
442 442
                         )
443 443
                     ),
444 444
                 );
445
-            } finally {
445
+            }finally{
446 446
                 $this->tracer->pop(true);
447 447
                 $this->tracer->pop(false);
448 448
             }
449
-            try {
449
+            try{
450 450
                 // Using constructor with resolved arguments
451 451
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
452 452
                 $this->tracer->push(true);
453 453
                 $instance = new $class(...$args);
454
-            } catch (\TypeError $e) {
454
+            }catch (\TypeError $e){
455 455
                 throw new WrongTypeException($constructor, $e);
456
-            } finally {
456
+            }finally{
457 457
                 $this->tracer->pop(true);
458 458
                 $this->tracer->pop(false);
459 459
             }
460
-        } else {
460
+        }else{
461 461
             // No constructor specified
462 462
             $instance = $reflection->newInstance();
463 463
         }
@@ -475,13 +475,13 @@  discard block
 block discarded – undo
475 475
         $instance = $this->runInflector($instance);
476 476
 
477 477
         //Declarative singletons
478
-        if ($this->isSingleton($ctx)) {
478
+        if ($this->isSingleton($ctx)){
479 479
             $this->state->singletons[$ctx->alias] = $instance;
480 480
         }
481 481
 
482 482
         // Register finalizer
483 483
         $finalizer = $this->getFinalizer($ctx, $instance);
484
-        if ($finalizer !== null) {
484
+        if ($finalizer !== null){
485 485
             $this->state->finalizers[] = $finalizer;
486 486
         }
487 487
 
@@ -493,12 +493,12 @@  discard block
 block discarded – undo
493 493
      */
494 494
     private function isSingleton(Ctx $ctx): bool
495 495
     {
496
-        if ($ctx->singleton === true) {
496
+        if ($ctx->singleton === true){
497 497
             return true;
498 498
         }
499 499
 
500 500
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
501
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
501
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class)){
502 502
             return true;
503 503
         }
504 504
 
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
          * @var Finalize|null $attribute
513 513
          */
514 514
         $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance();
515
-        if ($attribute === null) {
515
+        if ($attribute === null){
516 516
             return null;
517 517
         }
518 518
 
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
     {
527 527
         $scope = $this->scope;
528 528
 
529
-        while ($scope !== null) {
530
-            foreach ($this->state->inflectors as $class => $inflectors) {
531
-                if ($instance instanceof $class) {
532
-                    foreach ($inflectors as $inflector) {
529
+        while ($scope !== null){
530
+            foreach ($this->state->inflectors as $class => $inflectors){
531
+                if ($instance instanceof $class){
532
+                    foreach ($inflectors as $inflector){
533 533
                         $instance = $inflector->getParametersCount() > 1
534 534
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
535 535
                             : ($inflector->inflector)($instance);
@@ -545,9 +545,9 @@  discard block
 block discarded – undo
545 545
 
546 546
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
547 547
     {
548
-        try {
548
+        try{
549 549
             $this->resolver->validateArguments($reflection, $arguments);
550
-        } catch (\Throwable) {
550
+        }catch (\Throwable){
551 551
             return false;
552 552
         }
553 553
 
Please login to merge, or discard this patch.
Braces   +119 added lines, -51 removed lines patch added patch discarded remove patch
@@ -68,17 +68,20 @@  discard block
 block discarded – undo
68 68
      */
69 69
     public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed
70 70
     {
71
-        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) {
71
+        if ($parameters === [] && \array_key_exists($alias, $this->state->singletons))
72
+        {
72 73
             return $this->state->singletons[$alias];
73 74
         }
74 75
 
75 76
         $binding = $this->state->bindings[$alias] ?? null;
76 77
 
77
-        if ($binding === null) {
78
+        if ($binding === null)
79
+        {
78 80
             return $this->resolveWithoutBinding($alias, $parameters, $context);
79 81
         }
80 82
 
81
-        try {
83
+        try
84
+        {
82 85
             $this->tracer->push(
83 86
                 false,
84 87
                 action: 'resolve from binding',
@@ -106,7 +109,9 @@  discard block
 block discarded – undo
106 109
                     ->resolveWeakReference($binding, $alias, $context, $parameters),
107 110
                 default => $binding,
108 111
             };
109
-        } finally {
112
+        }
113
+        finally
114
+        {
110 115
             $this->state->bindings[$alias] ??= $binding;
111 116
             $this->tracer->pop(true);
112 117
             $this->tracer->pop(false);
@@ -120,18 +125,23 @@  discard block
 block discarded – undo
120 125
     private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments)
121 126
     {
122 127
         $context = $ctx->context;
123
-        try {
128
+        try
129
+        {
124 130
             $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class);
125
-        } catch (\ReflectionException $e) {
131
+        }
132
+        catch (\ReflectionException $e)
133
+        {
126 134
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
127 135
         }
128 136
 
129 137
         $injector = $binding->injector;
130 138
 
131
-        try {
139
+        try
140
+        {
132 141
             $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector);
133 142
 
134
-            if (!$injectorInstance instanceof InjectorInterface) {
143
+            if (!$injectorInstance instanceof InjectorInterface)
144
+            {
135 145
                 throw new InjectionException(
136 146
                     \sprintf(
137 147
                         "Class '%s' must be an instance of InjectorInterface for '%s'.",
@@ -158,7 +168,8 @@  discard block
 block discarded – undo
158 168
                 default => (string)$context,
159 169
             });
160 170
 
161
-            if (!$reflection->isInstance($instance)) {
171
+            if (!$reflection->isInstance($instance))
172
+            {
162 173
                 throw new InjectionException(
163 174
                     \sprintf(
164 175
                         "Invalid injection response for '%s'.",
@@ -168,7 +179,9 @@  discard block
 block discarded – undo
168 179
             }
169 180
 
170 181
             return $instance;
171
-        } finally {
182
+        }
183
+        finally
184
+        {
172 185
             $this->state->bindings[$ctx->class] ??= $binding;
173 186
         }
174 187
     }
@@ -187,7 +200,8 @@  discard block
 block discarded – undo
187 200
             //Binding is pointing to something else
188 201
             : $this->make($binding->alias, $arguments, $context);
189 202
 
190
-        if ($binding->singleton && $arguments === []) {
203
+        if ($binding->singleton && $arguments === [])
204
+        {
191 205
             $this->state->singletons[$alias] = $result;
192 206
         }
193 207
 
@@ -228,11 +242,14 @@  discard block
 block discarded – undo
228 242
         array $arguments,
229 243
     ): mixed {
230 244
         $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton);
231
-        try {
245
+        try
246
+        {
232 247
             $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0
233 248
                 ? ($binding->factory)()
234 249
                 : $this->invoker->invoke($binding->factory, $arguments);
235
-        } catch (NotCallableException $e) {
250
+        }
251
+        catch (NotCallableException $e)
252
+        {
236 253
             throw new ContainerException(
237 254
                 $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)),
238 255
                 $e->getCode(),
@@ -251,19 +268,24 @@  discard block
 block discarded – undo
251 268
     ): ?object {
252 269
         $avoidCache = $arguments !== [];
253 270
 
254
-        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) {
255
-            try {
271
+        if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias))
272
+        {
273
+            try
274
+            {
256 275
                 $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context);
257 276
 
258 277
                 $object = $this->createInstance(
259 278
                     new Ctx(alias: $alias, class: $alias, context: $context),
260 279
                     $arguments,
261 280
                 );
262
-                if ($avoidCache) {
281
+                if ($avoidCache)
282
+                {
263 283
                     return $object;
264 284
                 }
265 285
                 $binding->reference = WeakReference::create($object);
266
-            } catch (\Throwable) {
286
+            }
287
+            catch (\Throwable)
288
+            {
267 289
                 throw new ContainerException(
268 290
                     $this->tracer->combineTraceMessage(
269 291
                         \sprintf(
@@ -273,7 +295,9 @@  discard block
 block discarded – undo
273 295
                         )
274 296
                     )
275 297
                 );
276
-            } finally {
298
+            }
299
+            finally
300
+            {
277 301
                 $this->tracer->pop();
278 302
             }
279 303
         }
@@ -288,18 +312,25 @@  discard block
 block discarded – undo
288 312
     ): mixed {
289 313
         $parent = $this->scope->getParent();
290 314
 
291
-        if ($parent !== null) {
292
-            try {
315
+        if ($parent !== null)
316
+        {
317
+            try
318
+            {
293 319
                 $this->tracer->push(false, ...[
294 320
                     'current scope' => $this->scope->getScopeName(),
295 321
                     'jump to parent scope' => $this->scope->getParentScope()->getScopeName(),
296 322
                 ]);
297 323
                 return $parent->make($alias, $parameters, $context);
298
-            } catch (BadScopeException $e) {
299
-                if ($this->scope->getScopeName() !== $e->getScope()) {
324
+            }
325
+            catch (BadScopeException $e)
326
+            {
327
+                if ($this->scope->getScopeName() !== $e->getScope())
328
+                {
300 329
                     throw $e;
301 330
                 }
302
-            } catch (ContainerExceptionInterface $e) {
331
+            }
332
+            catch (ContainerExceptionInterface $e)
333
+            {
303 334
                 $className = match (true) {
304 335
                     $e instanceof NotFoundException => NotFoundException::class,
305 336
                     default => ContainerException::class,
@@ -308,19 +339,24 @@  discard block
 block discarded – undo
308 339
                     'Can\'t resolve `%s`.',
309 340
                     $alias,
310 341
                 )), previous: $e);
311
-            } finally {
342
+            }
343
+            finally
344
+            {
312 345
                 $this->tracer->pop(false);
313 346
             }
314 347
         }
315 348
 
316 349
         $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context);
317
-        try {
350
+        try
351
+        {
318 352
             //No direct instructions how to construct class, make is automatically
319 353
             return $this->autowire(
320 354
                 new Ctx(alias: $alias, class: $alias, context: $context),
321 355
                 $parameters,
322 356
             );
323
-        } finally {
357
+        }
358
+        finally
359
+        {
324 360
             $this->tracer->pop(false);
325 361
         }
326 362
     }
@@ -370,7 +406,8 @@  discard block
 block discarded – undo
370 406
         // Check scope name
371 407
         $ctx->reflection = new \ReflectionClass($instance);
372 408
         $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name;
373
-        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) {
409
+        if ($scopeName !== null && $scopeName !== $this->scope->getScopeName())
410
+        {
374 411
             throw new BadScopeException($scopeName, $instance::class);
375 412
         }
376 413
 
@@ -397,24 +434,30 @@  discard block
 block discarded – undo
397 434
         array $arguments,
398 435
     ): object {
399 436
         $class = $ctx->class;
400
-        try {
437
+        try
438
+        {
401 439
             $ctx->reflection = $reflection = new \ReflectionClass($class);
402
-        } catch (\ReflectionException $e) {
440
+        }
441
+        catch (\ReflectionException $e)
442
+        {
403 443
             throw new ContainerException($e->getMessage(), $e->getCode(), $e);
404 444
         }
405 445
 
406 446
         // Check scope name
407 447
         $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name;
408
-        if ($scope !== null && $scope !== $this->scope->getScopeName()) {
448
+        if ($scope !== null && $scope !== $this->scope->getScopeName())
449
+        {
409 450
             throw new BadScopeException($scope, $class);
410 451
         }
411 452
 
412 453
         // We have to construct class using external injector when we know the exact context
413
-        if ($arguments === [] && $this->binder->hasInjector($class)) {
454
+        if ($arguments === [] && $this->binder->hasInjector($class))
455
+        {
414 456
             return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
415 457
         }
416 458
 
417
-        if (!$reflection->isInstantiable()) {
459
+        if (!$reflection->isInstantiable())
460
+        {
418 461
             $itIs = match (true) {
419 462
                 $reflection->isEnum() => 'Enum',
420 463
                 $reflection->isAbstract() => 'Abstract class',
@@ -427,12 +470,16 @@  discard block
 block discarded – undo
427 470
 
428 471
         $constructor = $reflection->getConstructor();
429 472
 
430
-        if ($constructor !== null) {
431
-            try {
473
+        if ($constructor !== null)
474
+        {
475
+            try
476
+            {
432 477
                 $this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
433 478
                 $this->tracer->push(true);
434 479
                 $args = $this->resolver->resolveArguments($constructor, $arguments);
435
-            } catch (ValidationException $e) {
480
+            }
481
+            catch (ValidationException $e)
482
+            {
436 483
                 throw new ContainerException(
437 484
                     $this->tracer->combineTraceMessage(
438 485
                         \sprintf(
@@ -442,22 +489,31 @@  discard block
 block discarded – undo
442 489
                         )
443 490
                     ),
444 491
                 );
445
-            } finally {
492
+            }
493
+            finally
494
+            {
446 495
                 $this->tracer->pop(true);
447 496
                 $this->tracer->pop(false);
448 497
             }
449
-            try {
498
+            try
499
+            {
450 500
                 // Using constructor with resolved arguments
451 501
                 $this->tracer->push(false, call: "$class::__construct", arguments: $args);
452 502
                 $this->tracer->push(true);
453 503
                 $instance = new $class(...$args);
454
-            } catch (\TypeError $e) {
504
+            }
505
+            catch (\TypeError $e)
506
+            {
455 507
                 throw new WrongTypeException($constructor, $e);
456
-            } finally {
508
+            }
509
+            finally
510
+            {
457 511
                 $this->tracer->pop(true);
458 512
                 $this->tracer->pop(false);
459 513
             }
460
-        } else {
514
+        }
515
+        else
516
+        {
461 517
             // No constructor specified
462 518
             $instance = $reflection->newInstance();
463 519
         }
@@ -475,13 +531,15 @@  discard block
 block discarded – undo
475 531
         $instance = $this->runInflector($instance);
476 532
 
477 533
         //Declarative singletons
478
-        if ($this->isSingleton($ctx)) {
534
+        if ($this->isSingleton($ctx))
535
+        {
479 536
             $this->state->singletons[$ctx->alias] = $instance;
480 537
         }
481 538
 
482 539
         // Register finalizer
483 540
         $finalizer = $this->getFinalizer($ctx, $instance);
484
-        if ($finalizer !== null) {
541
+        if ($finalizer !== null)
542
+        {
485 543
             $this->state->finalizers[] = $finalizer;
486 544
         }
487 545
 
@@ -493,12 +551,14 @@  discard block
 block discarded – undo
493 551
      */
494 552
     private function isSingleton(Ctx $ctx): bool
495 553
     {
496
-        if ($ctx->singleton === true) {
554
+        if ($ctx->singleton === true)
555
+        {
497 556
             return true;
498 557
         }
499 558
 
500 559
         /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */
501
-        if ($ctx->reflection->implementsInterface(SingletonInterface::class)) {
560
+        if ($ctx->reflection->implementsInterface(SingletonInterface::class))
561
+        {
502 562
             return true;
503 563
         }
504 564
 
@@ -512,7 +572,8 @@  discard block
 block discarded – undo
512 572
          * @var Finalize|null $attribute
513 573
          */
514 574
         $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance();
515
-        if ($attribute === null) {
575
+        if ($attribute === null)
576
+        {
516 577
             return null;
517 578
         }
518 579
 
@@ -526,10 +587,14 @@  discard block
 block discarded – undo
526 587
     {
527 588
         $scope = $this->scope;
528 589
 
529
-        while ($scope !== null) {
530
-            foreach ($this->state->inflectors as $class => $inflectors) {
531
-                if ($instance instanceof $class) {
532
-                    foreach ($inflectors as $inflector) {
590
+        while ($scope !== null)
591
+        {
592
+            foreach ($this->state->inflectors as $class => $inflectors)
593
+            {
594
+                if ($instance instanceof $class)
595
+                {
596
+                    foreach ($inflectors as $inflector)
597
+                    {
533 598
                         $instance = $inflector->getParametersCount() > 1
534 599
                             ? $this->invoker->invoke($inflector->inflector, [$instance])
535 600
                             : ($inflector->inflector)($instance);
@@ -545,9 +610,12 @@  discard block
 block discarded – undo
545 610
 
546 611
     private function validateArguments(ContextFunction $reflection, array $arguments = []): bool
547 612
     {
548
-        try {
613
+        try
614
+        {
549 615
             $this->resolver->validateArguments($reflection, $arguments);
550
-        } catch (\Throwable) {
616
+        }
617
+        catch (\Throwable)
618
+        {
551 619
             return false;
552 620
         }
553 621
 
Please login to merge, or discard this patch.