@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | ): array { |
| 54 | 54 | $state = new ResolvingState($reflection, $parameters); |
| 55 | 55 | |
| 56 | - foreach ($reflection->getParameters() as $parameter) { |
|
| 56 | + foreach ($reflection->getParameters() as $parameter){ |
|
| 57 | 57 | $this->resolveParameter($parameter, $state, $validate) |
| 58 | 58 | or |
| 59 | 59 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +67,47 @@ discard block |
||
| 67 | 67 | $positional = true; |
| 68 | 68 | $variadic = false; |
| 69 | 69 | $parameters = $reflection->getParameters(); |
| 70 | - if (\count($parameters) === 0) { |
|
| 70 | + if (\count($parameters) === 0){ |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $parameter = null; |
| 75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
| 75 | + while (\count($parameters) > 0 || \count($arguments) > 0){ |
|
| 76 | 76 | // get related argument value |
| 77 | 77 | $key = \key($arguments); |
| 78 | 78 | |
| 79 | 79 | // For a variadic parameter it's no sense - named or positional argument will be sent |
| 80 | 80 | // But you can't send positional argument after named in any case |
| 81 | - if (\is_int($key) && !$positional) { |
|
| 81 | + if (\is_int($key) && !$positional){ |
|
| 82 | 82 | throw new PositionalArgumentException($reflection, $key); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $positional = $positional && \is_int($key); |
| 86 | 86 | |
| 87 | - if (!$variadic) { |
|
| 87 | + if (!$variadic){ |
|
| 88 | 88 | $parameter = \array_shift($parameters); |
| 89 | 89 | $variadic = $parameter?->isVariadic() ?? false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - if ($parameter === null) { |
|
| 92 | + if ($parameter === null){ |
|
| 93 | 93 | throw new UnknownParameterException($reflection, $key); |
| 94 | 94 | } |
| 95 | 95 | $name = $parameter->getName(); |
| 96 | 96 | |
| 97 | - if (($positional || $variadic) && $key !== null) { |
|
| 97 | + if (($positional || $variadic) && $key !== null){ |
|
| 98 | 98 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
| 99 | 99 | $value = \array_shift($arguments); |
| 100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
| 101 | - if ($parameter->isOptional()) { |
|
| 100 | + } elseif ($key === null || !\array_key_exists($name, $arguments)){ |
|
| 101 | + if ($parameter->isOptional()){ |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | throw new MissingRequiredArgumentException($reflection, $name); |
| 105 | - } else { |
|
| 105 | + }else{ |
|
| 106 | 106 | $value = &$arguments[$name]; |
| 107 | 107 | unset($arguments[$name]); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
| 110 | + if (!$this->validateValueToParameter($parameter, $value)){ |
|
| 111 | 111 | throw new InvalidArgumentException($reflection, $name); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
| 117 | 117 | { |
| 118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
| 118 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){ |
|
| 119 | 119 | return true; |
| 120 | 120 | } |
| 121 | 121 | $type = $parameter->getType(); |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
| 127 | 127 | }; |
| 128 | 128 | |
| 129 | - foreach ($types as $t) { |
|
| 129 | + foreach ($types as $t){ |
|
| 130 | 130 | \assert($t instanceof ReflectionNamedType); |
| 131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
| 131 | + if (!$this->validateValueNamedType($t, $value)){ |
|
| 132 | 132 | // If it is TypeIntersection |
| 133 | - if ($or) { |
|
| 133 | + if ($or){ |
|
| 134 | 134 | continue; |
| 135 | 135 | } |
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | // If it is not type intersection then we can skip that value after first successful check |
| 139 | - if ($or) { |
|
| 139 | + if ($or){ |
|
| 140 | 140 | return true; |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $name = $type->getName(); |
| 153 | 153 | |
| 154 | - if ($type->isBuiltin()) { |
|
| 154 | + if ($type->isBuiltin()){ |
|
| 155 | 155 | return match ($name) { |
| 156 | 156 | 'mixed' => true, |
| 157 | 157 | 'string' => \is_string($value), |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | // Try to resolve parameter by name |
| 186 | 186 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
| 187 | - if ($res !== [] || $isVariadic) { |
|
| 187 | + if ($res !== [] || $isVariadic){ |
|
| 188 | 188 | // validate |
| 189 | - if ($isVariadic) { |
|
| 190 | - foreach ($res as $k => &$v) { |
|
| 191 | - $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
|
| 189 | + if ($isVariadic){ |
|
| 190 | + foreach ($res as $k => &$v){ |
|
| 191 | + $this->processArgument($state, $v, validateWith: $validate ? $param : null, key : $k); |
|
| 192 | 192 | } |
| 193 | - } else { |
|
| 193 | + }else{ |
|
| 194 | 194 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -198,38 +198,38 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | $error = null; |
| 201 | - while ($hasType) { |
|
| 201 | + while ($hasType){ |
|
| 202 | 202 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
| 203 | 203 | $refType = $param->getType(); |
| 204 | 204 | |
| 205 | - if ($refType::class === ReflectionNamedType::class) { |
|
| 206 | - if ($refType->isBuiltin()) { |
|
| 205 | + if ($refType::class === ReflectionNamedType::class){ |
|
| 206 | + if ($refType->isBuiltin()){ |
|
| 207 | 207 | break; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (\interface_exists($refType->getName()) && !empty($param->getAttributes(ProxyAttribute::class))) { |
|
| 210 | + if (\interface_exists($refType->getName()) && !empty($param->getAttributes(ProxyAttribute::class))){ |
|
| 211 | 211 | $proxy = Proxy::create(new \ReflectionClass($refType->getName()), $param); |
| 212 | 212 | $this->processArgument($state, $proxy); |
| 213 | 213 | return true; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - try { |
|
| 217 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
| 216 | + try{ |
|
| 217 | + if ($this->resolveObject($state, $refType, $param, $validate)){ |
|
| 218 | 218 | return true; |
| 219 | 219 | } |
| 220 | - } catch (Throwable $e) { |
|
| 220 | + }catch (Throwable $e){ |
|
| 221 | 221 | $error = $e; |
| 222 | 222 | } |
| 223 | 223 | break; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ($refType::class === ReflectionUnionType::class) { |
|
| 227 | - foreach ($refType->getTypes() as $namedType) { |
|
| 228 | - try { |
|
| 229 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
| 226 | + if ($refType::class === ReflectionUnionType::class){ |
|
| 227 | + foreach ($refType->getTypes() as $namedType){ |
|
| 228 | + try{ |
|
| 229 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)){ |
|
| 230 | 230 | return true; |
| 231 | 231 | } |
| 232 | - } catch (Throwable $e) { |
|
| 232 | + }catch (Throwable $e){ |
|
| 233 | 233 | $error = $e; |
| 234 | 234 | } |
| 235 | 235 | } |
@@ -239,19 +239,19 @@ discard block |
||
| 239 | 239 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - if ($param->isDefaultValueAvailable()) { |
|
| 242 | + if ($param->isDefaultValueAvailable()){ |
|
| 243 | 243 | $argument = $param->getDefaultValue(); |
| 244 | 244 | $this->processArgument($state, $argument); |
| 245 | 245 | return true; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if ($hasType && $param->allowsNull()) { |
|
| 248 | + if ($hasType && $param->allowsNull()){ |
|
| 249 | 249 | $argument = null; |
| 250 | 250 | $this->processArgument($state, $argument); |
| 251 | 251 | return true; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - if ($error === null) { |
|
| 254 | + if ($error === null){ |
|
| 255 | 255 | return false; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -289,15 +289,15 @@ discard block |
||
| 289 | 289 | ResolvingState $state, |
| 290 | 290 | mixed &$value, |
| 291 | 291 | ReflectionParameter $validateWith = null, |
| 292 | - int|string $key = null |
|
| 292 | + int | string $key = null |
|
| 293 | 293 | ): void { |
| 294 | 294 | // Resolve Autowire objects |
| 295 | - if ($value instanceof Autowire) { |
|
| 295 | + if ($value instanceof Autowire){ |
|
| 296 | 296 | $value = $value->resolve($this->factory); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // Validation |
| 300 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
| 300 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){ |
|
| 301 | 301 | throw new InvalidArgumentException( |
| 302 | 302 | $validateWith->getDeclaringFunction(), |
| 303 | 303 | $validateWith->getName() |
@@ -53,7 +53,8 @@ discard block |
||
| 53 | 53 | ): array { |
| 54 | 54 | $state = new ResolvingState($reflection, $parameters); |
| 55 | 55 | |
| 56 | - foreach ($reflection->getParameters() as $parameter) { |
|
| 56 | + foreach ($reflection->getParameters() as $parameter) |
|
| 57 | + { |
|
| 57 | 58 | $this->resolveParameter($parameter, $state, $validate) |
| 58 | 59 | or |
| 59 | 60 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -67,47 +68,59 @@ discard block |
||
| 67 | 68 | $positional = true; |
| 68 | 69 | $variadic = false; |
| 69 | 70 | $parameters = $reflection->getParameters(); |
| 70 | - if (\count($parameters) === 0) { |
|
| 71 | + if (\count($parameters) === 0) |
|
| 72 | + { |
|
| 71 | 73 | return; |
| 72 | 74 | } |
| 73 | 75 | |
| 74 | 76 | $parameter = null; |
| 75 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
| 77 | + while (\count($parameters) > 0 || \count($arguments) > 0) |
|
| 78 | + { |
|
| 76 | 79 | // get related argument value |
| 77 | 80 | $key = \key($arguments); |
| 78 | 81 | |
| 79 | 82 | // For a variadic parameter it's no sense - named or positional argument will be sent |
| 80 | 83 | // But you can't send positional argument after named in any case |
| 81 | - if (\is_int($key) && !$positional) { |
|
| 84 | + if (\is_int($key) && !$positional) |
|
| 85 | + { |
|
| 82 | 86 | throw new PositionalArgumentException($reflection, $key); |
| 83 | 87 | } |
| 84 | 88 | |
| 85 | 89 | $positional = $positional && \is_int($key); |
| 86 | 90 | |
| 87 | - if (!$variadic) { |
|
| 91 | + if (!$variadic) |
|
| 92 | + { |
|
| 88 | 93 | $parameter = \array_shift($parameters); |
| 89 | 94 | $variadic = $parameter?->isVariadic() ?? false; |
| 90 | 95 | } |
| 91 | 96 | |
| 92 | - if ($parameter === null) { |
|
| 97 | + if ($parameter === null) |
|
| 98 | + { |
|
| 93 | 99 | throw new UnknownParameterException($reflection, $key); |
| 94 | 100 | } |
| 95 | 101 | $name = $parameter->getName(); |
| 96 | 102 | |
| 97 | - if (($positional || $variadic) && $key !== null) { |
|
| 103 | + if (($positional || $variadic) && $key !== null) |
|
| 104 | + { |
|
| 98 | 105 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
| 99 | 106 | $value = \array_shift($arguments); |
| 100 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
| 101 | - if ($parameter->isOptional()) { |
|
| 107 | + } |
|
| 108 | + elseif ($key === null || !\array_key_exists($name, $arguments)) |
|
| 109 | + { |
|
| 110 | + if ($parameter->isOptional()) |
|
| 111 | + { |
|
| 102 | 112 | continue; |
| 103 | 113 | } |
| 104 | 114 | throw new MissingRequiredArgumentException($reflection, $name); |
| 105 | - } else { |
|
| 115 | + } |
|
| 116 | + else |
|
| 117 | + { |
|
| 106 | 118 | $value = &$arguments[$name]; |
| 107 | 119 | unset($arguments[$name]); |
| 108 | 120 | } |
| 109 | 121 | |
| 110 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
| 122 | + if (!$this->validateValueToParameter($parameter, $value)) |
|
| 123 | + { |
|
| 111 | 124 | throw new InvalidArgumentException($reflection, $name); |
| 112 | 125 | } |
| 113 | 126 | } |
@@ -115,7 +128,8 @@ discard block |
||
| 115 | 128 | |
| 116 | 129 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
| 117 | 130 | { |
| 118 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
| 131 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) |
|
| 132 | + { |
|
| 119 | 133 | return true; |
| 120 | 134 | } |
| 121 | 135 | $type = $parameter->getType(); |
@@ -126,17 +140,21 @@ discard block |
||
| 126 | 140 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
| 127 | 141 | }; |
| 128 | 142 | |
| 129 | - foreach ($types as $t) { |
|
| 143 | + foreach ($types as $t) |
|
| 144 | + { |
|
| 130 | 145 | \assert($t instanceof ReflectionNamedType); |
| 131 | - if (!$this->validateValueNamedType($t, $value)) { |
|
| 146 | + if (!$this->validateValueNamedType($t, $value)) |
|
| 147 | + { |
|
| 132 | 148 | // If it is TypeIntersection |
| 133 | - if ($or) { |
|
| 149 | + if ($or) |
|
| 150 | + { |
|
| 134 | 151 | continue; |
| 135 | 152 | } |
| 136 | 153 | return false; |
| 137 | 154 | } |
| 138 | 155 | // If it is not type intersection then we can skip that value after first successful check |
| 139 | - if ($or) { |
|
| 156 | + if ($or) |
|
| 157 | + { |
|
| 140 | 158 | return true; |
| 141 | 159 | } |
| 142 | 160 | } |
@@ -151,7 +169,8 @@ discard block |
||
| 151 | 169 | { |
| 152 | 170 | $name = $type->getName(); |
| 153 | 171 | |
| 154 | - if ($type->isBuiltin()) { |
|
| 172 | + if ($type->isBuiltin()) |
|
| 173 | + { |
|
| 155 | 174 | return match ($name) { |
| 156 | 175 | 'mixed' => true, |
| 157 | 176 | 'string' => \is_string($value), |
@@ -184,13 +203,18 @@ discard block |
||
| 184 | 203 | |
| 185 | 204 | // Try to resolve parameter by name |
| 186 | 205 | $res = $state->resolveParameterByNameOrPosition($param, $isVariadic); |
| 187 | - if ($res !== [] || $isVariadic) { |
|
| 206 | + if ($res !== [] || $isVariadic) |
|
| 207 | + { |
|
| 188 | 208 | // validate |
| 189 | - if ($isVariadic) { |
|
| 190 | - foreach ($res as $k => &$v) { |
|
| 209 | + if ($isVariadic) |
|
| 210 | + { |
|
| 211 | + foreach ($res as $k => &$v) |
|
| 212 | + { |
|
| 191 | 213 | $this->processArgument($state, $v, validateWith: $validate ? $param : null, key: $k); |
| 192 | 214 | } |
| 193 | - } else { |
|
| 215 | + } |
|
| 216 | + else |
|
| 217 | + { |
|
| 194 | 218 | $this->processArgument($state, $res[0], validateWith: $validate ? $param : null); |
| 195 | 219 | } |
| 196 | 220 | |
@@ -198,38 +222,52 @@ discard block |
||
| 198 | 222 | } |
| 199 | 223 | |
| 200 | 224 | $error = null; |
| 201 | - while ($hasType) { |
|
| 225 | + while ($hasType) |
|
| 226 | + { |
|
| 202 | 227 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $refType */ |
| 203 | 228 | $refType = $param->getType(); |
| 204 | 229 | |
| 205 | - if ($refType::class === ReflectionNamedType::class) { |
|
| 206 | - if ($refType->isBuiltin()) { |
|
| 230 | + if ($refType::class === ReflectionNamedType::class) |
|
| 231 | + { |
|
| 232 | + if ($refType->isBuiltin()) |
|
| 233 | + { |
|
| 207 | 234 | break; |
| 208 | 235 | } |
| 209 | 236 | |
| 210 | - if (\interface_exists($refType->getName()) && !empty($param->getAttributes(ProxyAttribute::class))) { |
|
| 237 | + if (\interface_exists($refType->getName()) && !empty($param->getAttributes(ProxyAttribute::class))) |
|
| 238 | + { |
|
| 211 | 239 | $proxy = Proxy::create(new \ReflectionClass($refType->getName()), $param); |
| 212 | 240 | $this->processArgument($state, $proxy); |
| 213 | 241 | return true; |
| 214 | 242 | } |
| 215 | 243 | |
| 216 | - try { |
|
| 217 | - if ($this->resolveObject($state, $refType, $param, $validate)) { |
|
| 244 | + try |
|
| 245 | + { |
|
| 246 | + if ($this->resolveObject($state, $refType, $param, $validate)) |
|
| 247 | + { |
|
| 218 | 248 | return true; |
| 219 | 249 | } |
| 220 | - } catch (Throwable $e) { |
|
| 250 | + } |
|
| 251 | + catch (Throwable $e) |
|
| 252 | + { |
|
| 221 | 253 | $error = $e; |
| 222 | 254 | } |
| 223 | 255 | break; |
| 224 | 256 | } |
| 225 | 257 | |
| 226 | - if ($refType::class === ReflectionUnionType::class) { |
|
| 227 | - foreach ($refType->getTypes() as $namedType) { |
|
| 228 | - try { |
|
| 229 | - if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) { |
|
| 258 | + if ($refType::class === ReflectionUnionType::class) |
|
| 259 | + { |
|
| 260 | + foreach ($refType->getTypes() as $namedType) |
|
| 261 | + { |
|
| 262 | + try |
|
| 263 | + { |
|
| 264 | + if (!$namedType->isBuiltin() && $this->resolveObject($state, $namedType, $param, $validate)) |
|
| 265 | + { |
|
| 230 | 266 | return true; |
| 231 | 267 | } |
| 232 | - } catch (Throwable $e) { |
|
| 268 | + } |
|
| 269 | + catch (Throwable $e) |
|
| 270 | + { |
|
| 233 | 271 | $error = $e; |
| 234 | 272 | } |
| 235 | 273 | } |
@@ -239,19 +277,22 @@ discard block |
||
| 239 | 277 | throw new UnsupportedTypeException($param->getDeclaringFunction(), $param->getName()); |
| 240 | 278 | } |
| 241 | 279 | |
| 242 | - if ($param->isDefaultValueAvailable()) { |
|
| 280 | + if ($param->isDefaultValueAvailable()) |
|
| 281 | + { |
|
| 243 | 282 | $argument = $param->getDefaultValue(); |
| 244 | 283 | $this->processArgument($state, $argument); |
| 245 | 284 | return true; |
| 246 | 285 | } |
| 247 | 286 | |
| 248 | - if ($hasType && $param->allowsNull()) { |
|
| 287 | + if ($hasType && $param->allowsNull()) |
|
| 288 | + { |
|
| 249 | 289 | $argument = null; |
| 250 | 290 | $this->processArgument($state, $argument); |
| 251 | 291 | return true; |
| 252 | 292 | } |
| 253 | 293 | |
| 254 | - if ($error === null) { |
|
| 294 | + if ($error === null) |
|
| 295 | + { |
|
| 255 | 296 | return false; |
| 256 | 297 | } |
| 257 | 298 | |
@@ -292,12 +333,14 @@ discard block |
||
| 292 | 333 | int|string $key = null |
| 293 | 334 | ): void { |
| 294 | 335 | // Resolve Autowire objects |
| 295 | - if ($value instanceof Autowire) { |
|
| 336 | + if ($value instanceof Autowire) |
|
| 337 | + { |
|
| 296 | 338 | $value = $value->resolve($this->factory); |
| 297 | 339 | } |
| 298 | 340 | |
| 299 | 341 | // Validation |
| 300 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
| 342 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) |
|
| 343 | + { |
|
| 301 | 344 | throw new InvalidArgumentException( |
| 302 | 345 | $validateWith->getDeclaringFunction(), |
| 303 | 346 | $validateWith->getName() |
@@ -16,23 +16,23 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | $interface = $type->getName(); |
| 18 | 18 | $classBody = []; |
| 19 | - foreach ($type->getMethods() as $method) { |
|
| 20 | - if ($method->isConstructor()) { |
|
| 19 | + foreach ($type->getMethods() as $method){ |
|
| 20 | + if ($method->isConstructor()){ |
|
| 21 | 21 | continue; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $hasRefs = false; |
| 25 | 25 | $return = $method->hasReturnType() && (string)$method->getReturnType() === 'void' ? '' : 'return '; |
| 26 | - $call = ($method->isStatic() ? '::' : '->') . $method->getName(); |
|
| 26 | + $call = ($method->isStatic() ? '::' : '->').$method->getName(); |
|
| 27 | 27 | $context = $method->isStatic() ? 'null' : '$this->__container_proxy_context'; |
| 28 | 28 | |
| 29 | 29 | $args = []; |
| 30 | - foreach ($method->getParameters() as $param) { |
|
| 30 | + foreach ($method->getParameters() as $param){ |
|
| 31 | 31 | $hasRefs = $hasRefs || $param->isPassedByReference(); |
| 32 | - $args[] = ($param->isVariadic() ? '...' : '') . '$'. $param->getName(); |
|
| 32 | + $args[] = ($param->isVariadic() ? '...' : '').'$'.$param->getName(); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if (!$hasRefs && !$method->isVariadic()) { |
|
| 35 | + if (!$hasRefs && !$method->isVariadic()){ |
|
| 36 | 36 | $classBody[] = self::renderMethod($method, <<<PHP |
| 37 | 37 | {$return}\\Spiral\\Core\\Internal\\Proxy\\Resolver::resolve( |
| 38 | 38 | '{$interface}', |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $argsStr = \implode(', ', $args); |
| 46 | 46 | |
| 47 | - if ($method->isVariadic()) { |
|
| 47 | + if ($method->isVariadic()){ |
|
| 48 | 48 | $classBody[] = self::renderMethod($method, <<<PHP |
| 49 | 49 | {$return}\\Spiral\\Core\\Internal\\Proxy\\Resolver::resolve( |
| 50 | 50 | '{$interface}', |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $m->getName(), |
| 84 | 84 | \implode(', ', \array_map([self::class, 'renderParameter'], $m->getParameters())), |
| 85 | 85 | $m->hasReturnType() |
| 86 | - ? ': ' . self::renderParameterTypes($m->getReturnType(), $m->getDeclaringClass()) |
|
| 86 | + ? ': '.self::renderParameterTypes($m->getReturnType(), $m->getDeclaringClass()) |
|
| 87 | 87 | : '', |
| 88 | 88 | $body, |
| 89 | 89 | ); |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | $param->hasType() ? self::renderParameterTypes($param->getType(), $param->getDeclaringClass()) : '', |
| 97 | 97 | $param->isPassedByReference() ? '&' : '', |
| 98 | 98 | $param->isVariadic() ? '...' : '', |
| 99 | - '$' . $param->getName(), |
|
| 100 | - $param->isOptional() && !$param->isVariadic() ? ' = ' . self::renderDefaultValue($param) : '', |
|
| 99 | + '$'.$param->getName(), |
|
| 100 | + $param->isOptional() && !$param->isVariadic() ? ' = '.self::renderDefaultValue($param) : '', |
|
| 101 | 101 | ), ' '); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | public static function renderParameterTypes(\ReflectionType $types, \ReflectionClass $class): string |
| 105 | 105 | { |
| 106 | - if ($types instanceof \ReflectionNamedType) { |
|
| 107 | - return ($types->allowsNull() && $types->getName() !== 'mixed' ? '?' : '') . ($types->isBuiltin() |
|
| 106 | + if ($types instanceof \ReflectionNamedType){ |
|
| 107 | + return ($types->allowsNull() && $types->getName() !== 'mixed' ? '?' : '').($types->isBuiltin() |
|
| 108 | 108 | ? $types->getName() |
| 109 | 109 | : self::normalizeClassType($types, $class)); |
| 110 | 110 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | }; |
| 117 | 117 | |
| 118 | 118 | $result = []; |
| 119 | - foreach ($types as $type) { |
|
| 119 | + foreach ($types as $type){ |
|
| 120 | 120 | $result[] = $type->isBuiltin() |
| 121 | 121 | ? $type->getName() |
| 122 | 122 | : self::normalizeClassType($type, $class); |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | public static function renderDefaultValue(\ReflectionParameter $param): string |
| 129 | 129 | { |
| 130 | - if ($param->isDefaultValueConstant()) { |
|
| 130 | + if ($param->isDefaultValueConstant()){ |
|
| 131 | 131 | $result = $param->getDefaultValueConstantName(); |
| 132 | 132 | |
| 133 | 133 | return \explode('::', $result)[0] === 'self' |
| 134 | 134 | ? $result |
| 135 | - : '\\' . $result; |
|
| 135 | + : '\\'.$result; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | $cut = self::cutDefaultValue($param); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | public static function normalizeClassType(\ReflectionNamedType $type, \ReflectionClass $class): string |
| 146 | 146 | { |
| 147 | - return '\\' . ($type->getName() === 'self' ? $class->getName() : $type->getName()); |
|
| 147 | + return '\\'.($type->getName() === 'self' ? $class->getName() : $type->getName()); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | private static function cutDefaultValue(\ReflectionParameter $param): string |
@@ -16,8 +16,10 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | $interface = $type->getName(); |
| 18 | 18 | $classBody = []; |
| 19 | - foreach ($type->getMethods() as $method) { |
|
| 20 | - if ($method->isConstructor()) { |
|
| 19 | + foreach ($type->getMethods() as $method) |
|
| 20 | + { |
|
| 21 | + if ($method->isConstructor()) |
|
| 22 | + { |
|
| 21 | 23 | continue; |
| 22 | 24 | } |
| 23 | 25 | |
@@ -27,12 +29,14 @@ discard block |
||
| 27 | 29 | $context = $method->isStatic() ? 'null' : '$this->__container_proxy_context'; |
| 28 | 30 | |
| 29 | 31 | $args = []; |
| 30 | - foreach ($method->getParameters() as $param) { |
|
| 32 | + foreach ($method->getParameters() as $param) |
|
| 33 | + { |
|
| 31 | 34 | $hasRefs = $hasRefs || $param->isPassedByReference(); |
| 32 | 35 | $args[] = ($param->isVariadic() ? '...' : '') . '$'. $param->getName(); |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | - if (!$hasRefs && !$method->isVariadic()) { |
|
| 38 | + if (!$hasRefs && !$method->isVariadic()) |
|
| 39 | + { |
|
| 36 | 40 | $classBody[] = self::renderMethod($method, <<<PHP |
| 37 | 41 | {$return}\\Spiral\\Core\\Internal\\Proxy\\Resolver::resolve( |
| 38 | 42 | '{$interface}', |
@@ -44,7 +48,8 @@ discard block |
||
| 44 | 48 | |
| 45 | 49 | $argsStr = \implode(', ', $args); |
| 46 | 50 | |
| 47 | - if ($method->isVariadic()) { |
|
| 51 | + if ($method->isVariadic()) |
|
| 52 | + { |
|
| 48 | 53 | $classBody[] = self::renderMethod($method, <<<PHP |
| 49 | 54 | {$return}\\Spiral\\Core\\Internal\\Proxy\\Resolver::resolve( |
| 50 | 55 | '{$interface}', |
@@ -103,7 +108,8 @@ discard block |
||
| 103 | 108 | |
| 104 | 109 | public static function renderParameterTypes(\ReflectionType $types, \ReflectionClass $class): string |
| 105 | 110 | { |
| 106 | - if ($types instanceof \ReflectionNamedType) { |
|
| 111 | + if ($types instanceof \ReflectionNamedType) |
|
| 112 | + { |
|
| 107 | 113 | return ($types->allowsNull() && $types->getName() !== 'mixed' ? '?' : '') . ($types->isBuiltin() |
| 108 | 114 | ? $types->getName() |
| 109 | 115 | : self::normalizeClassType($types, $class)); |
@@ -116,7 +122,8 @@ discard block |
||
| 116 | 122 | }; |
| 117 | 123 | |
| 118 | 124 | $result = []; |
| 119 | - foreach ($types as $type) { |
|
| 125 | + foreach ($types as $type) |
|
| 126 | + { |
|
| 120 | 127 | $result[] = $type->isBuiltin() |
| 121 | 128 | ? $type->getName() |
| 122 | 129 | : self::normalizeClassType($type, $class); |
@@ -127,7 +134,8 @@ discard block |
||
| 127 | 134 | |
| 128 | 135 | public static function renderDefaultValue(\ReflectionParameter $param): string |
| 129 | 136 | { |
| 130 | - if ($param->isDefaultValueConstant()) { |
|
| 137 | + if ($param->isDefaultValueConstant()) |
|
| 138 | + { |
|
| 131 | 139 | $result = $param->getDefaultValueConstantName(); |
| 132 | 140 | |
| 133 | 141 | return \explode('::', $result)[0] === 'self' |
@@ -12,15 +12,15 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | final class Resolver |
| 14 | 14 | { |
| 15 | - public static function resolve(string $alias, \Stringable|string|null $context = null): object |
|
| 15 | + public static function resolve(string $alias, \Stringable | string | null $context = null): object |
|
| 16 | 16 | { |
| 17 | 17 | $c = ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.'); |
| 18 | 18 | |
| 19 | - try { |
|
| 19 | + try{ |
|
| 20 | 20 | $result = $c->get($alias, $context) ?? throw new ContainerException( |
| 21 | 21 | 'Resolved `null` from the container.', |
| 22 | 22 | ); |
| 23 | - } catch (ContainerException $e) { |
|
| 23 | + }catch (ContainerException $e){ |
|
| 24 | 24 | throw new ContainerException( |
| 25 | 25 | // todo : find required scope |
| 26 | 26 | \sprintf('Unable to resolve `%s` in a Proxy.', $alias), |
@@ -16,11 +16,14 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $c = ContainerScope::getContainer() ?? throw new ContainerException('Proxy is out of scope.'); |
| 18 | 18 | |
| 19 | - try { |
|
| 19 | + try |
|
| 20 | + { |
|
| 20 | 21 | $result = $c->get($alias, $context) ?? throw new ContainerException( |
| 21 | 22 | 'Resolved `null` from the container.', |
| 22 | 23 | ); |
| 23 | - } catch (ContainerException $e) { |
|
| 24 | + } |
|
| 25 | + catch (ContainerException $e) |
|
| 26 | + { |
|
| 24 | 27 | throw new ContainerException( |
| 25 | 28 | // todo : find required scope |
| 26 | 29 | \sprintf('Unable to resolve `%s` in a Proxy.', $alias), |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | trait ProxyTrait |
| 14 | 14 | { |
| 15 | 15 | private static string $__container_proxy_alias; |
| 16 | - private \Stringable|string|null $__container_proxy_context = null; |
|
| 16 | + private \Stringable | string | null $__container_proxy_context = null; |
|
| 17 | 17 | |
| 18 | 18 | public function __call(string $name, array $arguments) |
| 19 | 19 | { |