Total Complexity | 5 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
15 | final class Handler |
||
16 | { |
||
17 | /** |
||
18 | * @var callable |
||
19 | */ |
||
20 | private $action; |
||
21 | |||
22 | /** |
||
23 | * @var \ReflectionParameter[] |
||
24 | */ |
||
25 | private $parameters; |
||
26 | |||
27 | /** |
||
28 | * @param callable $action |
||
29 | * @param array $parameters |
||
30 | */ |
||
31 | 11 | public function __construct(callable $action, array $parameters = []) |
|
35 | 11 | } |
|
36 | |||
37 | /** |
||
38 | * @param callable $action |
||
39 | * |
||
40 | * @return self |
||
41 | */ |
||
42 | 10 | public static function recognize(callable $action): self |
|
43 | { |
||
44 | 10 | $reflection = new \ReflectionMethod(\Closure::fromCallable($action), '__invoke'); |
|
45 | |||
46 | 10 | return new self($action, $reflection->getParameters()); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param \Throwable $error |
||
51 | * |
||
52 | * @return self |
||
53 | */ |
||
54 | public static function error(\Throwable $error): self |
||
55 | { |
||
56 | 1 | return new self(function () use ($error) { |
|
57 | 1 | throw $error; |
|
58 | 1 | }); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return \ReflectionParameter[] |
||
63 | */ |
||
64 | 4 | public function parameters(): array |
|
65 | { |
||
66 | 4 | return $this->parameters; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * @param mixed ...$arguments |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | 7 | public function __invoke(...$arguments) |
|
79 | } |
||
80 | } |
||
81 |