Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
15 | class Action |
||
16 | { |
||
17 | private static array $valid_actions = [ |
||
18 | 'set', |
||
19 | 'unset', |
||
20 | 'reset', |
||
21 | 'handle', |
||
22 | 'cron', |
||
23 | 'webhookinfo', |
||
24 | ]; |
||
25 | |||
26 | private string $action; |
||
27 | |||
28 | /** |
||
29 | * @throws InvalidActionException |
||
30 | */ |
||
31 | public function __construct(?string $action = 'handle') |
||
32 | { |
||
33 | $this->action = $action ?: 'handle'; |
||
34 | |||
35 | if (!$this->isAction(self::$valid_actions)) { |
||
36 | throw new InvalidActionException('Invalid action: ' . $this->action); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | public function isAction(array|string $actions): bool |
||
41 | { |
||
42 | return in_array($this->action, (array) $actions, true); |
||
43 | } |
||
44 | |||
45 | public function getAction(): string |
||
46 | { |
||
47 | return $this->action; |
||
48 | } |
||
49 | |||
50 | public static function getValidActions(): array |
||
53 | } |
||
54 | } |
||
55 |