Action::getAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the TelegramBotManager package.
4
 *
5
 * (c) Armando Lüscher <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace TelegramBot\TelegramBotManager;
12
13
use TelegramBot\TelegramBotManager\Exception\InvalidActionException;
14
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
51
    {
52
        return self::$valid_actions;
53
    }
54
}
55