@@ -13,7 +13,7 @@ |
||
13 | 13 | { |
14 | 14 | public function __construct( |
15 | 15 | private LoggerInterface $logger, |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function createInjection(\ReflectionClass $class, ?string $context = null): LoggerInterface |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function testInvalidInjector(): void |
38 | 38 | { |
39 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
39 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
40 | 40 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
41 | 41 | $this->expectException(InjectionException::class); |
42 | 42 | $this->expectExceptionMessage($excepted); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function testInvalidRuntimeInjector(): void |
64 | 64 | { |
65 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
65 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
66 | 66 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
67 | 67 | $this->expectException(InjectionException::class); |
68 | 68 | $this->expectExceptionMessage($excepted); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $container->bind(ConfigsInterface::class, $configurator); |
100 | 100 | |
101 | 101 | $configurator->shouldReceive('createInjection') |
102 | - ->with(m::on(static function (ReflectionClass $r) { |
|
102 | + ->with(m::on(static function (ReflectionClass $r){ |
|
103 | 103 | return $r->getName() === TestConfig::class; |
104 | 104 | }), null) |
105 | 105 | ->andReturn($expected); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $container->bind(ConfigsInterface::class, $configurator); |
117 | 117 | |
118 | 118 | $configurator->shouldReceive('createInjection') |
119 | - ->with(m::on(static function (ReflectionClass $r) { |
|
119 | + ->with(m::on(static function (ReflectionClass $r){ |
|
120 | 120 | return $r->getName() === TestConfig::class; |
121 | 121 | }), 'context') |
122 | 122 | ->andReturn($expected); |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | { |
136 | 136 | $container = new Container(); |
137 | 137 | |
138 | - try { |
|
138 | + try{ |
|
139 | 139 | $container->get('invalid'); |
140 | - } catch (ContainerException $e) { |
|
140 | + }catch (ContainerException $e){ |
|
141 | 141 | $this->assertSame( |
142 | 142 | <<<MARKDOWN |
143 | 143 | Can't resolve `invalid`: undefined class or binding `invalid`. |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | { |
170 | 170 | $this->expectException(ContainerException::class); |
171 | 171 | |
172 | - try { |
|
172 | + try{ |
|
173 | 173 | $container->get(ClassWithUndefinedDependency::class); |
174 | - } catch (ContainerException $e) { |
|
174 | + }catch (ContainerException $e){ |
|
175 | 175 | self::assertSame($message, $e->getMessage()); |
176 | 176 | |
177 | 177 | throw $e; |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | public function hasInstance(string $alias): bool |
30 | 30 | { |
31 | - if (!$this->container->has($alias)) { |
|
31 | + if (!$this->container->has($alias)){ |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | public array $info = [], |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | $this->alias = $info['alias'] ?? null; |
24 | 24 | } |
25 | 25 | |
26 | 26 | public function __toString(): string |
27 | 27 | { |
28 | 28 | $info = []; |
29 | - foreach ($this->info as $key => $item) { |
|
29 | + foreach ($this->info as $key => $item){ |
|
30 | 30 | $info[] = "$key: {$this->stringifyValue($item)}"; |
31 | 31 | } |
32 | 32 | return \implode("\n", $info); |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | \is_scalar($item) => \var_export($item, true), |
40 | 40 | $item instanceof \Closure => $this->renderClosureSignature(new \ReflectionFunction($item)), |
41 | 41 | $item instanceof \ReflectionFunctionAbstract => $this->renderClosureSignature($item), |
42 | - $item instanceof \UnitEnum => $item::class . "::$item->name", |
|
43 | - \is_object($item) => $item instanceof \Stringable ? (string) $item : 'instance of ' . $item::class, |
|
42 | + $item instanceof \UnitEnum => $item::class."::$item->name", |
|
43 | + \is_object($item) => $item instanceof \Stringable ? (string)$item : 'instance of '.$item::class, |
|
44 | 44 | \is_array($item) => $this->renderArray($item), |
45 | 45 | default => \get_debug_type($item), |
46 | 46 | }; |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | |
49 | 49 | private function renderArray(array $array, int $level = 0): string |
50 | 50 | { |
51 | - if ($array === []) { |
|
51 | + if ($array === []){ |
|
52 | 52 | return '[]'; |
53 | 53 | } |
54 | - if ($level >= self::ARRAY_MAX_LEVEL) { |
|
54 | + if ($level >= self::ARRAY_MAX_LEVEL){ |
|
55 | 55 | return 'array'; |
56 | 56 | } |
57 | 57 | $result = []; |
58 | - foreach ($array as $key => $value) { |
|
58 | + foreach ($array as $key => $value){ |
|
59 | 59 | $result[] = \sprintf( |
60 | 60 | '%s: %s', |
61 | 61 | $key, |
@@ -66,6 +66,6 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $pad = \str_repeat(' ', $level); |
69 | - return "[\n $pad" . \implode(",\n $pad", $result) . "\n$pad]"; |
|
69 | + return "[\n $pad".\implode(",\n $pad", $result)."\n$pad]"; |
|
70 | 70 | } |
71 | 71 | } |
@@ -52,7 +52,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 ($this->resolveNamedType($state, $parameter, $namedType, $validate)) { |
|
209 | + foreach ($types as $namedType){ |
|
210 | + try{ |
|
211 | + if ($this->resolveNamedType($state, $parameter, $namedType, $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 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | ReflectionParameter $parameter, |
251 | 251 | ReflectionNamedType $typeRef, |
252 | 252 | bool $validate, |
253 | - ) { |
|
253 | + ){ |
|
254 | 254 | return !$typeRef->isBuiltin() && $this->resolveObjectParameter( |
255 | 255 | $state, |
256 | 256 | $typeRef->getName(), |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | ResolvingState $state, |
294 | 294 | mixed &$value, |
295 | 295 | ReflectionParameter $validateWith = null, |
296 | - int|string $key = null |
|
296 | + int | string $key = null |
|
297 | 297 | ): void { |
298 | 298 | // Resolve Autowire objects |
299 | - if ($value instanceof Autowire) { |
|
299 | + if ($value instanceof Autowire){ |
|
300 | 300 | $value = $value->resolve($this->factory); |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Validation |
304 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
304 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){ |
|
305 | 305 | throw new InvalidArgumentException( |
306 | 306 | $validateWith->getDeclaringFunction(), |
307 | 307 | $validateWith->getName() |
@@ -7,8 +7,8 @@ |
||
7 | 7 | final class Scalar extends Binding |
8 | 8 | { |
9 | 9 | public function __construct( |
10 | - public readonly bool|int|string|float $value, |
|
11 | - ) { |
|
10 | + public readonly bool | int | string | float $value, |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function __toString(): string |
@@ -17,8 +17,8 @@ |
||
17 | 17 | * @param string|InjectorInterface $injector Injector object or binding alias. |
18 | 18 | */ |
19 | 19 | public function __construct( |
20 | - public readonly string|InjectorInterface $injector, |
|
21 | - ) { |
|
20 | + public readonly string | InjectorInterface $injector, |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function __toString(): string |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function __construct( |
20 | 20 | public readonly \Closure $inflector, |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | $this->parametersCount = (new \ReflectionFunction($inflector))->getNumberOfParameters(); |
23 | 23 | } |
24 | 24 |