@@ -39,7 +39,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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]; |
@@ -12,7 +12,7 @@ |
||
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 | } |
@@ -19,7 +19,7 @@ discard block |
||
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 |
||
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 |
@@ -49,7 +49,8 @@ |
||
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 |
@@ -66,19 +66,19 @@ discard block |
||
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 |
||
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); |
@@ -116,18 +116,18 @@ discard block |
||
116 | 116 | private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments) |
117 | 117 | { |
118 | 118 | $context = $ctx->context; |
119 | - try { |
|
119 | + try{ |
|
120 | 120 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
121 | - } catch (\ReflectionException $e) { |
|
121 | + }catch (\ReflectionException $e){ |
|
122 | 122 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $injector = $binding->injector; |
126 | 126 | |
127 | - try { |
|
127 | + try{ |
|
128 | 128 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
129 | 129 | |
130 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
130 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
131 | 131 | throw new InjectionException( |
132 | 132 | \sprintf( |
133 | 133 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | default => (string)$context, |
156 | 156 | }); |
157 | 157 | |
158 | - if (!$reflection->isInstance($instance)) { |
|
158 | + if (!$reflection->isInstance($instance)){ |
|
159 | 159 | throw new InjectionException( |
160 | 160 | \sprintf( |
161 | 161 | "Invalid injection response for '%s'.", |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | return $instance; |
168 | - } finally { |
|
168 | + }finally{ |
|
169 | 169 | $this->state->bindings[$reflection->getName()] ??= $binding; |
170 | 170 | } |
171 | 171 | } |
@@ -173,18 +173,18 @@ discard block |
||
173 | 173 | private function resolveAlias( |
174 | 174 | \Spiral\Core\Config\Alias $binding, |
175 | 175 | string $alias, |
176 | - Stringable|string|null $context, |
|
176 | + Stringable | string | null $context, |
|
177 | 177 | array $arguments, |
178 | 178 | ): mixed { |
179 | 179 | $result = $binding->alias === $alias |
180 | 180 | ? $this->autowire( |
181 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
181 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
182 | 182 | $arguments, |
183 | 183 | ) |
184 | 184 | //Binding is pointing to something else |
185 | 185 | : $this->make($binding->alias, $arguments, $context); |
186 | 186 | |
187 | - if ($binding->singleton && $arguments === []) { |
|
187 | + if ($binding->singleton && $arguments === []){ |
|
188 | 188 | $this->state->singletons[$alias] = $result; |
189 | 189 | } |
190 | 190 | |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | private function resolveShared( |
195 | 195 | \Spiral\Core\Config\Shared $binding, |
196 | 196 | string $alias, |
197 | - Stringable|string|null $context, |
|
197 | + Stringable | string | null $context, |
|
198 | 198 | array $arguments, |
199 | 199 | ): object { |
200 | 200 | $avoidCache = $arguments !== []; |
201 | 201 | return $avoidCache |
202 | 202 | ? $this->createInstance( |
203 | - new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
|
203 | + new Ctx(alias : $alias, class : $binding->value::class, context : $context), |
|
204 | 204 | $arguments, |
205 | 205 | ) |
206 | 206 | : $binding->value; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | private function resolveAutowire( |
210 | 210 | \Spiral\Core\Config\Autowire $binding, |
211 | 211 | string $alias, |
212 | - Stringable|string|null $context, |
|
212 | + Stringable | string | null $context, |
|
213 | 213 | array $arguments, |
214 | 214 | ): mixed { |
215 | 215 | $instance = $binding->autowire->resolve($this, $arguments); |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | private function resolveFactory( |
222 | - \Spiral\Core\Config\Factory|DeferredFactory $binding, |
|
222 | + \Spiral\Core\Config\Factory | DeferredFactory $binding, |
|
223 | 223 | string $alias, |
224 | - Stringable|string|null $context, |
|
224 | + Stringable | string | null $context, |
|
225 | 225 | array $arguments, |
226 | 226 | ): mixed { |
227 | 227 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
228 | - try { |
|
228 | + try{ |
|
229 | 229 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
230 | 230 | ? ($binding->factory)() |
231 | 231 | : $this->invoker->invoke($binding->factory, $arguments); |
232 | - } catch (NotCallableException $e) { |
|
232 | + }catch (NotCallableException $e){ |
|
233 | 233 | throw new ContainerException( |
234 | 234 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
235 | 235 | $e->getCode(), |
@@ -243,24 +243,24 @@ discard block |
||
243 | 243 | private function resolveWeakReference( |
244 | 244 | \Spiral\Core\Config\WeakReference $binding, |
245 | 245 | string $alias, |
246 | - Stringable|string|null $context, |
|
246 | + Stringable | string | null $context, |
|
247 | 247 | array $arguments, |
248 | 248 | ): ?object { |
249 | 249 | $avoidCache = $arguments !== []; |
250 | 250 | |
251 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
252 | - try { |
|
251 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
252 | + try{ |
|
253 | 253 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
254 | 254 | |
255 | 255 | $object = $this->createInstance( |
256 | 256 | new Ctx(alias: $alias, class: $alias, context: $context), |
257 | 257 | $arguments, |
258 | 258 | ); |
259 | - if ($avoidCache) { |
|
259 | + if ($avoidCache){ |
|
260 | 260 | return $object; |
261 | 261 | } |
262 | 262 | $binding->reference = WeakReference::create($object); |
263 | - } catch (\Throwable) { |
|
263 | + }catch (\Throwable){ |
|
264 | 264 | throw new ContainerException( |
265 | 265 | $this->tracer->combineTraceMessage( |
266 | 266 | \sprintf( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ) |
271 | 271 | ) |
272 | 272 | ); |
273 | - } finally { |
|
273 | + }finally{ |
|
274 | 274 | $this->tracer->pop(); |
275 | 275 | } |
276 | 276 | } |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | private function resolveWithoutBinding( |
282 | 282 | string $alias, |
283 | 283 | array $parameters = [], |
284 | - Stringable|string|null $context = null |
|
284 | + Stringable | string | null $context = null |
|
285 | 285 | ): mixed { |
286 | 286 | $parent = $this->scope->getParent(); |
287 | 287 | |
288 | - if ($parent !== null) { |
|
289 | - try { |
|
288 | + if ($parent !== null){ |
|
289 | + try{ |
|
290 | 290 | $this->tracer->push(false, ...[ |
291 | 291 | 'current scope' => $this->scope->getScopeName(), |
292 | 292 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
293 | 293 | ]); |
294 | 294 | return $parent->make($alias, $parameters, $context); |
295 | - } catch (BadScopeException $e) { |
|
296 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
295 | + }catch (BadScopeException $e){ |
|
296 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
297 | 297 | throw $e; |
298 | 298 | } |
299 | - } catch (ContainerExceptionInterface $e) { |
|
299 | + }catch (ContainerExceptionInterface $e){ |
|
300 | 300 | $className = match (true) { |
301 | 301 | $e instanceof NotFoundException => NotFoundException::class, |
302 | 302 | default => ContainerException::class, |
@@ -305,19 +305,19 @@ discard block |
||
305 | 305 | 'Can\'t resolve `%s`.', |
306 | 306 | $alias, |
307 | 307 | )), previous: $e); |
308 | - } finally { |
|
308 | + }finally{ |
|
309 | 309 | $this->tracer->pop(false); |
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | 313 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
314 | - try { |
|
314 | + try{ |
|
315 | 315 | //No direct instructions how to construct class, make is automatically |
316 | 316 | return $this->autowire( |
317 | 317 | new Ctx(alias: $alias, class: $alias, context: $context), |
318 | 318 | $parameters, |
319 | 319 | ); |
320 | - } finally { |
|
320 | + }finally{ |
|
321 | 321 | $this->tracer->pop(false); |
322 | 322 | } |
323 | 323 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | && |
339 | 339 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
340 | 340 | )) |
341 | - ) { |
|
341 | + ){ |
|
342 | 342 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
343 | 343 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
344 | 344 | $this->tracer->getRootAlias(), |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | // Check scope name |
368 | 368 | $ctx->reflection = new \ReflectionClass($instance); |
369 | 369 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
370 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
370 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
371 | 371 | throw new BadScopeException($scopeName, $instance::class); |
372 | 372 | } |
373 | 373 | |
@@ -394,24 +394,24 @@ discard block |
||
394 | 394 | array $parameters, |
395 | 395 | ): object { |
396 | 396 | $class = $ctx->class; |
397 | - try { |
|
397 | + try{ |
|
398 | 398 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
399 | - } catch (\ReflectionException $e) { |
|
399 | + }catch (\ReflectionException $e){ |
|
400 | 400 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Check scope name |
404 | 404 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
405 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
405 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
406 | 406 | throw new BadScopeException($scope, $class); |
407 | 407 | } |
408 | 408 | |
409 | 409 | //We have to construct class using external injector when we know exact context |
410 | - if ($this->binder->hasInjector($class)) { |
|
410 | + if ($this->binder->hasInjector($class)){ |
|
411 | 411 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $parameters); |
412 | 412 | } |
413 | 413 | |
414 | - if (!$reflection->isInstantiable()) { |
|
414 | + if (!$reflection->isInstantiable()){ |
|
415 | 415 | $itIs = match (true) { |
416 | 416 | $reflection->isEnum() => 'Enum', |
417 | 417 | $reflection->isAbstract() => 'Abstract class', |
@@ -424,12 +424,12 @@ discard block |
||
424 | 424 | |
425 | 425 | $constructor = $reflection->getConstructor(); |
426 | 426 | |
427 | - if ($constructor !== null) { |
|
428 | - try { |
|
427 | + if ($constructor !== null){ |
|
428 | + try{ |
|
429 | 429 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
430 | 430 | $this->tracer->push(true); |
431 | 431 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
432 | - } catch (ValidationException $e) { |
|
432 | + }catch (ValidationException $e){ |
|
433 | 433 | throw new ContainerException( |
434 | 434 | $this->tracer->combineTraceMessage( |
435 | 435 | \sprintf( |
@@ -439,22 +439,22 @@ discard block |
||
439 | 439 | ) |
440 | 440 | ), |
441 | 441 | ); |
442 | - } finally { |
|
442 | + }finally{ |
|
443 | 443 | $this->tracer->pop(true); |
444 | 444 | $this->tracer->pop(false); |
445 | 445 | } |
446 | - try { |
|
446 | + try{ |
|
447 | 447 | // Using constructor with resolved arguments |
448 | 448 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
449 | 449 | $this->tracer->push(true); |
450 | 450 | $instance = new $class(...$arguments); |
451 | - } catch (\TypeError $e) { |
|
451 | + }catch (\TypeError $e){ |
|
452 | 452 | throw new WrongTypeException($constructor, $e); |
453 | - } finally { |
|
453 | + }finally{ |
|
454 | 454 | $this->tracer->pop(true); |
455 | 455 | $this->tracer->pop(false); |
456 | 456 | } |
457 | - } else { |
|
457 | + }else{ |
|
458 | 458 | // No constructor specified |
459 | 459 | $instance = $reflection->newInstance(); |
460 | 460 | } |
@@ -472,13 +472,13 @@ discard block |
||
472 | 472 | $instance = $this->runInflector($instance); |
473 | 473 | |
474 | 474 | //Declarative singletons |
475 | - if ($this->isSingleton($ctx)) { |
|
475 | + if ($this->isSingleton($ctx)){ |
|
476 | 476 | $this->state->singletons[$ctx->alias] = $instance; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // Register finalizer |
480 | 480 | $finalizer = $this->getFinalizer($ctx, $instance); |
481 | - if ($finalizer !== null) { |
|
481 | + if ($finalizer !== null){ |
|
482 | 482 | $this->state->finalizers[] = $finalizer; |
483 | 483 | } |
484 | 484 | |
@@ -490,12 +490,12 @@ discard block |
||
490 | 490 | */ |
491 | 491 | private function isSingleton(Ctx $ctx): bool |
492 | 492 | { |
493 | - if ($ctx->singleton === true) { |
|
493 | + if ($ctx->singleton === true){ |
|
494 | 494 | return true; |
495 | 495 | } |
496 | 496 | |
497 | 497 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
498 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
498 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
499 | 499 | return true; |
500 | 500 | } |
501 | 501 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | * @var Finalize|null $attribute |
510 | 510 | */ |
511 | 511 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
512 | - if ($attribute === null) { |
|
512 | + if ($attribute === null){ |
|
513 | 513 | return null; |
514 | 514 | } |
515 | 515 | |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | { |
524 | 524 | $scope = $this->scope; |
525 | 525 | |
526 | - while ($scope !== null) { |
|
527 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
528 | - if ($instance instanceof $class) { |
|
529 | - foreach ($inflectors as $inflector) { |
|
526 | + while ($scope !== null){ |
|
527 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
528 | + if ($instance instanceof $class){ |
|
529 | + foreach ($inflectors as $inflector){ |
|
530 | 530 | $instance = $inflector->getParametersCount() > 1 |
531 | 531 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
532 | 532 | : ($inflector->inflector)($instance); |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | |
543 | 543 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
544 | 544 | { |
545 | - try { |
|
545 | + try{ |
|
546 | 546 | $this->resolver->validateArguments($reflection, $arguments); |
547 | - } catch (\Throwable) { |
|
547 | + }catch (\Throwable){ |
|
548 | 548 | return false; |
549 | 549 | } |
550 | 550 |
@@ -68,17 +68,20 @@ discard block |
||
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 |
||
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); |
@@ -116,18 +121,23 @@ discard block |
||
116 | 121 | private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments) |
117 | 122 | { |
118 | 123 | $context = $ctx->context; |
119 | - try { |
|
124 | + try |
|
125 | + { |
|
120 | 126 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
121 | - } catch (\ReflectionException $e) { |
|
127 | + } |
|
128 | + catch (\ReflectionException $e) |
|
129 | + { |
|
122 | 130 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
123 | 131 | } |
124 | 132 | |
125 | 133 | $injector = $binding->injector; |
126 | 134 | |
127 | - try { |
|
135 | + try |
|
136 | + { |
|
128 | 137 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
129 | 138 | |
130 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
139 | + if (!$injectorInstance instanceof InjectorInterface) |
|
140 | + { |
|
131 | 141 | throw new InjectionException( |
132 | 142 | \sprintf( |
133 | 143 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -155,7 +165,8 @@ discard block |
||
155 | 165 | default => (string)$context, |
156 | 166 | }); |
157 | 167 | |
158 | - if (!$reflection->isInstance($instance)) { |
|
168 | + if (!$reflection->isInstance($instance)) |
|
169 | + { |
|
159 | 170 | throw new InjectionException( |
160 | 171 | \sprintf( |
161 | 172 | "Invalid injection response for '%s'.", |
@@ -165,7 +176,9 @@ discard block |
||
165 | 176 | } |
166 | 177 | |
167 | 178 | return $instance; |
168 | - } finally { |
|
179 | + } |
|
180 | + finally |
|
181 | + { |
|
169 | 182 | $this->state->bindings[$reflection->getName()] ??= $binding; |
170 | 183 | } |
171 | 184 | } |
@@ -184,7 +197,8 @@ discard block |
||
184 | 197 | //Binding is pointing to something else |
185 | 198 | : $this->make($binding->alias, $arguments, $context); |
186 | 199 | |
187 | - if ($binding->singleton && $arguments === []) { |
|
200 | + if ($binding->singleton && $arguments === []) |
|
201 | + { |
|
188 | 202 | $this->state->singletons[$alias] = $result; |
189 | 203 | } |
190 | 204 | |
@@ -225,11 +239,14 @@ discard block |
||
225 | 239 | array $arguments, |
226 | 240 | ): mixed { |
227 | 241 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
228 | - try { |
|
242 | + try |
|
243 | + { |
|
229 | 244 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
230 | 245 | ? ($binding->factory)() |
231 | 246 | : $this->invoker->invoke($binding->factory, $arguments); |
232 | - } catch (NotCallableException $e) { |
|
247 | + } |
|
248 | + catch (NotCallableException $e) |
|
249 | + { |
|
233 | 250 | throw new ContainerException( |
234 | 251 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
235 | 252 | $e->getCode(), |
@@ -248,19 +265,24 @@ discard block |
||
248 | 265 | ): ?object { |
249 | 266 | $avoidCache = $arguments !== []; |
250 | 267 | |
251 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
252 | - try { |
|
268 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
269 | + { |
|
270 | + try |
|
271 | + { |
|
253 | 272 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
254 | 273 | |
255 | 274 | $object = $this->createInstance( |
256 | 275 | new Ctx(alias: $alias, class: $alias, context: $context), |
257 | 276 | $arguments, |
258 | 277 | ); |
259 | - if ($avoidCache) { |
|
278 | + if ($avoidCache) |
|
279 | + { |
|
260 | 280 | return $object; |
261 | 281 | } |
262 | 282 | $binding->reference = WeakReference::create($object); |
263 | - } catch (\Throwable) { |
|
283 | + } |
|
284 | + catch (\Throwable) |
|
285 | + { |
|
264 | 286 | throw new ContainerException( |
265 | 287 | $this->tracer->combineTraceMessage( |
266 | 288 | \sprintf( |
@@ -270,7 +292,9 @@ discard block |
||
270 | 292 | ) |
271 | 293 | ) |
272 | 294 | ); |
273 | - } finally { |
|
295 | + } |
|
296 | + finally |
|
297 | + { |
|
274 | 298 | $this->tracer->pop(); |
275 | 299 | } |
276 | 300 | } |
@@ -285,18 +309,25 @@ discard block |
||
285 | 309 | ): mixed { |
286 | 310 | $parent = $this->scope->getParent(); |
287 | 311 | |
288 | - if ($parent !== null) { |
|
289 | - try { |
|
312 | + if ($parent !== null) |
|
313 | + { |
|
314 | + try |
|
315 | + { |
|
290 | 316 | $this->tracer->push(false, ...[ |
291 | 317 | 'current scope' => $this->scope->getScopeName(), |
292 | 318 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
293 | 319 | ]); |
294 | 320 | return $parent->make($alias, $parameters, $context); |
295 | - } catch (BadScopeException $e) { |
|
296 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
321 | + } |
|
322 | + catch (BadScopeException $e) |
|
323 | + { |
|
324 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
325 | + { |
|
297 | 326 | throw $e; |
298 | 327 | } |
299 | - } catch (ContainerExceptionInterface $e) { |
|
328 | + } |
|
329 | + catch (ContainerExceptionInterface $e) |
|
330 | + { |
|
300 | 331 | $className = match (true) { |
301 | 332 | $e instanceof NotFoundException => NotFoundException::class, |
302 | 333 | default => ContainerException::class, |
@@ -305,19 +336,24 @@ discard block |
||
305 | 336 | 'Can\'t resolve `%s`.', |
306 | 337 | $alias, |
307 | 338 | )), previous: $e); |
308 | - } finally { |
|
339 | + } |
|
340 | + finally |
|
341 | + { |
|
309 | 342 | $this->tracer->pop(false); |
310 | 343 | } |
311 | 344 | } |
312 | 345 | |
313 | 346 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
314 | - try { |
|
347 | + try |
|
348 | + { |
|
315 | 349 | //No direct instructions how to construct class, make is automatically |
316 | 350 | return $this->autowire( |
317 | 351 | new Ctx(alias: $alias, class: $alias, context: $context), |
318 | 352 | $parameters, |
319 | 353 | ); |
320 | - } finally { |
|
354 | + } |
|
355 | + finally |
|
356 | + { |
|
321 | 357 | $this->tracer->pop(false); |
322 | 358 | } |
323 | 359 | } |
@@ -367,7 +403,8 @@ discard block |
||
367 | 403 | // Check scope name |
368 | 404 | $ctx->reflection = new \ReflectionClass($instance); |
369 | 405 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
370 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
406 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
407 | + { |
|
371 | 408 | throw new BadScopeException($scopeName, $instance::class); |
372 | 409 | } |
373 | 410 | |
@@ -394,24 +431,30 @@ discard block |
||
394 | 431 | array $parameters, |
395 | 432 | ): object { |
396 | 433 | $class = $ctx->class; |
397 | - try { |
|
434 | + try |
|
435 | + { |
|
398 | 436 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
399 | - } catch (\ReflectionException $e) { |
|
437 | + } |
|
438 | + catch (\ReflectionException $e) |
|
439 | + { |
|
400 | 440 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
401 | 441 | } |
402 | 442 | |
403 | 443 | // Check scope name |
404 | 444 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
405 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
445 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
446 | + { |
|
406 | 447 | throw new BadScopeException($scope, $class); |
407 | 448 | } |
408 | 449 | |
409 | 450 | //We have to construct class using external injector when we know exact context |
410 | - if ($this->binder->hasInjector($class)) { |
|
451 | + if ($this->binder->hasInjector($class)) |
|
452 | + { |
|
411 | 453 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $parameters); |
412 | 454 | } |
413 | 455 | |
414 | - if (!$reflection->isInstantiable()) { |
|
456 | + if (!$reflection->isInstantiable()) |
|
457 | + { |
|
415 | 458 | $itIs = match (true) { |
416 | 459 | $reflection->isEnum() => 'Enum', |
417 | 460 | $reflection->isAbstract() => 'Abstract class', |
@@ -424,12 +467,16 @@ discard block |
||
424 | 467 | |
425 | 468 | $constructor = $reflection->getConstructor(); |
426 | 469 | |
427 | - if ($constructor !== null) { |
|
428 | - try { |
|
470 | + if ($constructor !== null) |
|
471 | + { |
|
472 | + try |
|
473 | + { |
|
429 | 474 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
430 | 475 | $this->tracer->push(true); |
431 | 476 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
432 | - } catch (ValidationException $e) { |
|
477 | + } |
|
478 | + catch (ValidationException $e) |
|
479 | + { |
|
433 | 480 | throw new ContainerException( |
434 | 481 | $this->tracer->combineTraceMessage( |
435 | 482 | \sprintf( |
@@ -439,22 +486,31 @@ discard block |
||
439 | 486 | ) |
440 | 487 | ), |
441 | 488 | ); |
442 | - } finally { |
|
489 | + } |
|
490 | + finally |
|
491 | + { |
|
443 | 492 | $this->tracer->pop(true); |
444 | 493 | $this->tracer->pop(false); |
445 | 494 | } |
446 | - try { |
|
495 | + try |
|
496 | + { |
|
447 | 497 | // Using constructor with resolved arguments |
448 | 498 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
449 | 499 | $this->tracer->push(true); |
450 | 500 | $instance = new $class(...$arguments); |
451 | - } catch (\TypeError $e) { |
|
501 | + } |
|
502 | + catch (\TypeError $e) |
|
503 | + { |
|
452 | 504 | throw new WrongTypeException($constructor, $e); |
453 | - } finally { |
|
505 | + } |
|
506 | + finally |
|
507 | + { |
|
454 | 508 | $this->tracer->pop(true); |
455 | 509 | $this->tracer->pop(false); |
456 | 510 | } |
457 | - } else { |
|
511 | + } |
|
512 | + else |
|
513 | + { |
|
458 | 514 | // No constructor specified |
459 | 515 | $instance = $reflection->newInstance(); |
460 | 516 | } |
@@ -472,13 +528,15 @@ discard block |
||
472 | 528 | $instance = $this->runInflector($instance); |
473 | 529 | |
474 | 530 | //Declarative singletons |
475 | - if ($this->isSingleton($ctx)) { |
|
531 | + if ($this->isSingleton($ctx)) |
|
532 | + { |
|
476 | 533 | $this->state->singletons[$ctx->alias] = $instance; |
477 | 534 | } |
478 | 535 | |
479 | 536 | // Register finalizer |
480 | 537 | $finalizer = $this->getFinalizer($ctx, $instance); |
481 | - if ($finalizer !== null) { |
|
538 | + if ($finalizer !== null) |
|
539 | + { |
|
482 | 540 | $this->state->finalizers[] = $finalizer; |
483 | 541 | } |
484 | 542 | |
@@ -490,12 +548,14 @@ discard block |
||
490 | 548 | */ |
491 | 549 | private function isSingleton(Ctx $ctx): bool |
492 | 550 | { |
493 | - if ($ctx->singleton === true) { |
|
551 | + if ($ctx->singleton === true) |
|
552 | + { |
|
494 | 553 | return true; |
495 | 554 | } |
496 | 555 | |
497 | 556 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
498 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
557 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
558 | + { |
|
499 | 559 | return true; |
500 | 560 | } |
501 | 561 | |
@@ -509,7 +569,8 @@ discard block |
||
509 | 569 | * @var Finalize|null $attribute |
510 | 570 | */ |
511 | 571 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
512 | - if ($attribute === null) { |
|
572 | + if ($attribute === null) |
|
573 | + { |
|
513 | 574 | return null; |
514 | 575 | } |
515 | 576 | |
@@ -523,10 +584,14 @@ discard block |
||
523 | 584 | { |
524 | 585 | $scope = $this->scope; |
525 | 586 | |
526 | - while ($scope !== null) { |
|
527 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
528 | - if ($instance instanceof $class) { |
|
529 | - foreach ($inflectors as $inflector) { |
|
587 | + while ($scope !== null) |
|
588 | + { |
|
589 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
590 | + { |
|
591 | + if ($instance instanceof $class) |
|
592 | + { |
|
593 | + foreach ($inflectors as $inflector) |
|
594 | + { |
|
530 | 595 | $instance = $inflector->getParametersCount() > 1 |
531 | 596 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
532 | 597 | : ($inflector->inflector)($instance); |
@@ -542,9 +607,12 @@ discard block |
||
542 | 607 | |
543 | 608 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
544 | 609 | { |
545 | - try { |
|
610 | + try |
|
611 | + { |
|
546 | 612 | $this->resolver->validateArguments($reflection, $arguments); |
547 | - } catch (\Throwable) { |
|
613 | + } |
|
614 | + catch (\Throwable) |
|
615 | + { |
|
548 | 616 | return false; |
549 | 617 | } |
550 | 618 |
@@ -17,9 +17,9 @@ |
||
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 | } |
@@ -34,24 +34,24 @@ discard block |
||
34 | 34 | yield [$from(fn(string $string = self::STRING_CONST) => 0), 'string $string = self::STRING_CONST']; |
35 | 35 | yield [ |
36 | 36 | $from(fn(string $string = ProxyClassRendererTest::STRING_CONST) => 0), |
37 | - 'string $string = \\' . self::class . '::STRING_CONST', |
|
37 | + 'string $string = \\'.self::class.'::STRING_CONST', |
|
38 | 38 | ]; |
39 | - yield [$from(fn(string|int $string = self::INT_CONST) => 0), 'string|int $string = self::INT_CONST']; |
|
39 | + yield [$from(fn(string | int $string = self::INT_CONST) => 0), 'string|int $string = self::INT_CONST']; |
|
40 | 40 | yield [$from(fn(mixed $string = 42) => 0), 'mixed $string = 42']; |
41 | 41 | yield [$from(fn(int $string = 42) => 0), 'int $string = 42']; |
42 | 42 | yield [$from(fn(float $string = 42) => 0), 'float $string = 42.0']; |
43 | 43 | yield [$from(fn(?bool $string = false) => 0), '?bool $string = false']; |
44 | - yield [$from(fn(bool|null $string = true) => 0), '?bool $string = true']; |
|
44 | + yield [$from(fn(bool | null $string = true) => 0), '?bool $string = true']; |
|
45 | 45 | yield [$from(fn(object $string = null) => 0), '?object $string = NULL']; |
46 | 46 | yield [$from(fn(iterable $string = null) => 0), '?iterable $string = NULL']; |
47 | 47 | yield [$from(fn(Countable&ArrayAccess $val) => 0), '\Countable&\ArrayAccess $val']; |
48 | 48 | yield [$from(fn(string ...$val) => 0), 'string ...$val']; |
49 | - yield [$from(fn(string|int ...$val) => 0), 'string|int ...$val']; |
|
50 | - yield [$from(fn(string|int &$link) => 0), 'string|int &$link']; |
|
49 | + yield [$from(fn(string | int ...$val) => 0), 'string|int ...$val']; |
|
50 | + yield [$from(fn(string | int &$link) => 0), 'string|int &$link']; |
|
51 | 51 | yield [$from(self::withSelf(...)), \sprintf('\%s $self = new self()', self::class)]; |
52 | 52 | yield [$from(fn(object $link = new \stdClass()) => 0), 'object $link = new \stdClass()']; |
53 | 53 | yield [ |
54 | - $from(fn(#[Proxy] float|int|\stdClass|null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0), |
|
54 | + $from(fn(#[Proxy] float | int | \stdClass | null $string = new \stdClass(1, 2, bar: "\n'zero")) => 0), |
|
55 | 55 | "\stdClass|int|float|null \$string = new \stdClass(1, 2, bar: '\n\'zero')", |
56 | 56 | ]; |
57 | 57 | yield [ |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | public const INT_CONST = 42; |
77 | 77 | |
78 | 78 | #[ExpectedAttribute('public function test1(...$variadic)')] |
79 | - public function test1(...$variadic) {} |
|
79 | + public function test1(...$variadic){} |
|
80 | 80 | #[ExpectedAttribute('public function test2(string|int $string = self::INT_CONST): string|int')] |
81 | - public function test2(string|int $string = self::INT_CONST): string|int {} |
|
81 | + public function test2(string | int $string = self::INT_CONST): string | int {} |
|
82 | 82 | #[ExpectedAttribute('public function test3(object $obj = new \stdClass(new \stdClass(), new \stdClass()))')] |
83 | - public function test3(object $obj = new stdClass(new stdClass(), new stdClass())) {} |
|
84 | - #[ExpectedAttribute('public function test4(): \\' . ProxyClassRendererTest::class)] |
|
83 | + public function test3(object $obj = new stdClass(new stdClass(), new stdClass())){} |
|
84 | + #[ExpectedAttribute('public function test4(): \\'.ProxyClassRendererTest::class)] |
|
85 | 85 | public function test4(): ProxyClassRendererTest {} |
86 | 86 | #[ExpectedAttribute('public function &test5(): string')] |
87 | 87 | public function &test5(): string {} |
88 | 88 | }; |
89 | 89 | |
90 | - foreach ((new \ReflectionClass($class))->getMethods() as $method) { |
|
90 | + foreach ((new \ReflectionClass($class))->getMethods() as $method){ |
|
91 | 91 | $expected = $method->getAttributes(ExpectedAttribute::class)[0]->newInstance(); |
92 | 92 | |
93 | 93 | yield [$method, $expected->value]; |
@@ -117,6 +117,6 @@ discard block |
||
117 | 117 | { |
118 | 118 | public function __construct( |
119 | 119 | public readonly string $value, |
120 | - ) { |
|
120 | + ){ |
|
121 | 121 | } |
122 | 122 | } |
@@ -72,22 +72,28 @@ |
||
72 | 72 | |
73 | 73 | public static function provideRenderMethod(): iterable |
74 | 74 | { |
75 | - $class = new class { |
|
75 | + $class = new class |
|
76 | + { |
|
76 | 77 | public const INT_CONST = 42; |
77 | 78 | |
78 | 79 | #[ExpectedAttribute('public function test1(...$variadic)')] |
79 | - public function test1(...$variadic) {} |
|
80 | + public function test1(...$variadic) |
|
81 | + { |
|
82 | +} |
|
80 | 83 | #[ExpectedAttribute('public function test2(string|int $string = self::INT_CONST): string|int')] |
81 | 84 | public function test2(string|int $string = self::INT_CONST): string|int {} |
82 | 85 | #[ExpectedAttribute('public function test3(object $obj = new \stdClass(new \stdClass(), new \stdClass()))')] |
83 | - public function test3(object $obj = new stdClass(new stdClass(), new stdClass())) {} |
|
86 | + public function test3(object $obj = new stdClass(new stdClass(), new stdClass())) |
|
87 | + { |
|
88 | +} |
|
84 | 89 | #[ExpectedAttribute('public function test4(): \\' . ProxyClassRendererTest::class)] |
85 | 90 | public function test4(): ProxyClassRendererTest {} |
86 | 91 | #[ExpectedAttribute('public function &test5(): string')] |
87 | 92 | public function &test5(): string {} |
88 | 93 | }; |
89 | 94 | |
90 | - foreach ((new \ReflectionClass($class))->getMethods() as $method) { |
|
95 | + foreach ((new \ReflectionClass($class))->getMethods() as $method) |
|
96 | + { |
|
91 | 97 | $expected = $method->getAttributes(ExpectedAttribute::class)[0]->newInstance(); |
92 | 98 | |
93 | 99 | yield [$method, $expected->value]; |
@@ -71,7 +71,7 @@ |
||
71 | 71 | $proxy = $$var; |
72 | 72 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
73 | 73 | self::assertSame( |
74 | - ['foo' => 'foo','zap' => 'bar', 'gas' => 69], |
|
74 | + ['foo' => 'foo', 'zap' => 'bar', 'gas' => 69], |
|
75 | 75 | $proxy->extraVariadic(foo: 'foo', zap: 'bar', gas: 69), |
76 | 76 | ); |
77 | 77 | }); |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
29 | 29 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
30 | 30 | |
31 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
31 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
32 | + { |
|
32 | 33 | /** @var MockInterfaceImpl $proxy */ |
33 | 34 | $proxy = $$var; |
34 | 35 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -47,7 +48,8 @@ discard block |
||
47 | 48 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
48 | 49 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
49 | 50 | |
50 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
51 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
52 | + { |
|
51 | 53 | /** @var MockInterfaceImpl $proxy */ |
52 | 54 | $proxy = $$var; |
53 | 55 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extra('foo', 'bar', 'baz', 69)); |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
67 | 69 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
68 | 70 | |
69 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
71 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
72 | + { |
|
70 | 73 | /** @var MockInterfaceImpl $proxy */ |
71 | 74 | $proxy = $$var; |
72 | 75 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
@@ -90,7 +93,8 @@ discard block |
||
90 | 93 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
91 | 94 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
92 | 95 | |
93 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
96 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
97 | + { |
|
94 | 98 | /** @var MockInterfaceImpl $proxy */ |
95 | 99 | $proxy = $$var; |
96 | 100 | $str = 'bar'; |
@@ -112,7 +116,8 @@ discard block |
||
112 | 116 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
113 | 117 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
114 | 118 | |
115 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
119 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
120 | + { |
|
116 | 121 | /** @var MockInterfaceImpl $proxy */ |
117 | 122 | $proxy = $$var; |
118 | 123 | |
@@ -137,7 +142,8 @@ discard block |
||
137 | 142 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
138 | 143 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
139 | 144 | |
140 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
145 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
146 | + { |
|
141 | 147 | /** @var MockInterfaceImpl $proxy */ |
142 | 148 | $proxy = $$var; |
143 | 149 | $str1 = 'bar'; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | return $name; |
16 | 16 | } |
17 | 17 | |
18 | - public function qux(int|string $age = 42): string|int |
|
18 | + public function qux(int | string $age = 42): string | int |
|
19 | 19 | { |
20 | 20 | return $age; |
21 | 21 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function concat(string $prefix, string &$byLink): array |
39 | 39 | { |
40 | - $byLink = $prefix . $byLink; |
|
40 | + $byLink = $prefix.$byLink; |
|
41 | 41 | return \func_get_args(); |
42 | 42 | } |
43 | 43 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | public function concatMultiple(string $prefix, string &...$byLink): array |
50 | 50 | { |
51 | - foreach ($byLink as $k => $link) { |
|
52 | - $byLink[$k] = $prefix . $link; |
|
51 | + foreach ($byLink as $k => $link){ |
|
52 | + $byLink[$k] = $prefix.$link; |
|
53 | 53 | unset($link); |
54 | 54 | } |
55 | 55 |
@@ -48,7 +48,8 @@ |
||
48 | 48 | |
49 | 49 | public function concatMultiple(string $prefix, string &...$byLink): array |
50 | 50 | { |
51 | - foreach ($byLink as $k => $link) { |
|
51 | + foreach ($byLink as $k => $link) |
|
52 | + { |
|
52 | 53 | $byLink[$k] = $prefix . $link; |
53 | 54 | unset($link); |
54 | 55 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | public function baz(string $name, int $age): string; |
14 | 14 | |
15 | - public function qux(string|int $age = 42): string|int; |
|
15 | + public function qux(string | int $age = 42): string | int; |
|
16 | 16 | |
17 | 17 | public function space(mixed $test age = 42): mixed; |
18 | 18 |