@@ -89,9 +89,12 @@ discard block |
||
89 | 89 | new ExceptionInterceptor(), |
90 | 90 | ], self::createMock(CoreInterface::class)); |
91 | 91 | |
92 | - try { |
|
92 | + try |
|
93 | + { |
|
93 | 94 | $pipeline->callAction('controller', 'action'); |
94 | - } catch (\RuntimeException) { |
|
95 | + } |
|
96 | + catch (\RuntimeException) |
|
97 | + { |
|
95 | 98 | // Attributes won't be lost after legacy interceptor |
96 | 99 | self::assertSame(['key' => 'value'], $state->context->getAttributes()); |
97 | 100 | } |
@@ -111,7 +114,8 @@ discard block |
||
111 | 114 | $lastHandler instanceof CoreInterface and $pipeline = $pipeline->withCore($lastHandler); |
112 | 115 | $lastHandler instanceof HandlerInterface and $pipeline = $pipeline->withHandler($lastHandler); |
113 | 116 | |
114 | - foreach ($interceptors as $interceptor) { |
|
117 | + foreach ($interceptors as $interceptor) |
|
118 | + { |
|
115 | 119 | $pipeline->addInterceptor($interceptor); |
116 | 120 | } |
117 | 121 |
@@ -34,14 +34,16 @@ discard block |
||
34 | 34 | { |
35 | 35 | // Resolve controller method |
36 | 36 | $method = $context->getTarget()->getReflection(); |
37 | - if ($method === null) { |
|
37 | + if ($method === null) |
|
38 | + { |
|
38 | 39 | $this->resolveFromPath or throw new TargetCallException( |
39 | 40 | "Reflection not provided for target `{$context->getTarget()}`.", |
40 | 41 | TargetCallException::NOT_FOUND, |
41 | 42 | ); |
42 | 43 | |
43 | 44 | $path = $context->getTarget()->getPath(); |
44 | - if (\count($path) !== 2) { |
|
45 | + if (\count($path) !== 2) |
|
46 | + { |
|
45 | 47 | throw new TargetCallException( |
46 | 48 | "Invalid target path to resolve reflection for `{$context->getTarget()}`." |
47 | 49 | . ' Expected two parts: class and method.', |
@@ -52,13 +54,15 @@ discard block |
||
52 | 54 | $method = ActionResolver::pathToReflection(\reset($path), \end($path)); |
53 | 55 | } |
54 | 56 | |
55 | - if ($method instanceof \ReflectionFunction) { |
|
57 | + if ($method instanceof \ReflectionFunction) |
|
58 | + { |
|
56 | 59 | $method->invokeArgs( |
57 | 60 | $this->resolveArguments($method, $context) |
58 | 61 | ); |
59 | 62 | } |
60 | 63 | |
61 | - if (!$method instanceof \ReflectionMethod) { |
|
64 | + if (!$method instanceof \ReflectionMethod) |
|
65 | + { |
|
62 | 66 | throw new TargetCallException("Action not found for target `{$context->getTarget()}`."); |
63 | 67 | } |
64 | 68 |
@@ -7,7 +7,8 @@ |
||
7 | 7 | // Load the original class to make an alias |
8 | 8 | use Spiral\Interceptors\Exception\TargetCallException; |
9 | 9 | |
10 | -if (!\class_exists(TargetCallException::class)) { |
|
10 | +if (!\class_exists(TargetCallException::class)) |
|
11 | +{ |
|
11 | 12 | /** |
12 | 13 | * Unable to perform user action or find controller. |
13 | 14 | * |
@@ -5,7 +5,8 @@ |
||
5 | 5 | namespace Spiral\Core\Exception; |
6 | 6 | |
7 | 7 | // Load the original class to make an alias |
8 | -if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)) { |
|
8 | +if (!\class_exists(\Spiral\Interceptors\Exception\InterceptorException::class)) |
|
9 | +{ |
|
9 | 10 | /** |
10 | 11 | * @deprecated will be removed in Spiral v4.0 |
11 | 12 | * Use {@see \Spiral\Interceptors\Exception\InterceptorException} instead. |
@@ -59,13 +59,15 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function callAction(string $controller, string $action, array $parameters = []): mixed |
61 | 61 | { |
62 | - if ($this->context === null) { |
|
62 | + if ($this->context === null) |
|
63 | + { |
|
63 | 64 | return $this->handle( |
64 | 65 | new CallContext(Target::fromPathArray([$controller, $action]), $parameters), |
65 | 66 | ); |
66 | 67 | } |
67 | 68 | |
68 | - if ($this->context->getTarget()->getPath() === [$controller, $action]) { |
|
69 | + if ($this->context->getTarget()->getPath() === [$controller, $action]) |
|
70 | + { |
|
69 | 71 | return $this->handle($this->context->withArguments($parameters)); |
70 | 72 | } |
71 | 73 | |
@@ -81,13 +83,15 @@ discard block |
||
81 | 83 | */ |
82 | 84 | public function handle(CallContext $context): mixed |
83 | 85 | { |
84 | - if ($this->core === null && $this->handler === null) { |
|
86 | + if ($this->core === null && $this->handler === null) |
|
87 | + { |
|
85 | 88 | throw new InterceptorException('Unable to invoke pipeline without last handler.'); |
86 | 89 | } |
87 | 90 | |
88 | 91 | $path = $context->getTarget()->getPath(); |
89 | 92 | |
90 | - if (isset($this->interceptors[$this->position])) { |
|
93 | + if (isset($this->interceptors[$this->position])) |
|
94 | + { |
|
91 | 95 | $interceptor = $this->interceptors[$this->position]; |
92 | 96 | $handler = $this->nextWithContext($context); |
93 | 97 |
@@ -41,7 +41,8 @@ discard block |
||
41 | 41 | $method = ActionResolver::pathToReflection($controller, $action); |
42 | 42 | |
43 | 43 | // Validate method |
44 | - if ($method->isStatic() || !$method->isPublic()) { |
|
44 | + if ($method->isStatic() || !$method->isPublic()) |
|
45 | + { |
|
45 | 46 | throw new ControllerException( |
46 | 47 | \sprintf( |
47 | 48 | 'Invalid action `%s`->`%s`', |
@@ -52,15 +53,20 @@ discard block |
||
52 | 53 | ); |
53 | 54 | } |
54 | 55 | |
55 | - try { |
|
56 | + try |
|
57 | + { |
|
56 | 58 | $args = $this->resolveArguments($method, $parameters); |
57 | - } catch (ArgumentResolvingException|InvalidArgumentException $e) { |
|
59 | + } |
|
60 | + catch (ArgumentResolvingException|InvalidArgumentException $e) |
|
61 | + { |
|
58 | 62 | throw new ControllerException( |
59 | 63 | \sprintf('Missing/invalid parameter %s of `%s`->`%s`', $e->getParameter(), $controller, $action), |
60 | 64 | ControllerException::BAD_ARGUMENT, |
61 | 65 | $e, |
62 | 66 | ); |
63 | - } catch (ContainerExceptionInterface $e) { |
|
67 | + } |
|
68 | + catch (ContainerExceptionInterface $e) |
|
69 | + { |
|
64 | 70 | throw new ControllerException( |
65 | 71 | $e->getMessage(), |
66 | 72 | ControllerException::ERROR, |
@@ -78,7 +84,8 @@ discard block |
||
78 | 84 | |
79 | 85 | protected function resolveArguments(\ReflectionMethod $method, array $parameters): array |
80 | 86 | { |
81 | - foreach ($method->getParameters() as $parameter) { |
|
87 | + foreach ($method->getParameters() as $parameter) |
|
88 | + { |
|
82 | 89 | $name = $parameter->getName(); |
83 | 90 | if ( |
84 | 91 | \array_key_exists($name, $parameters) && |