Action   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 15
c 0
b 0
f 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValidActions() 0 3 1
A getAction() 0 3 1
A __construct() 0 6 3
A isAction() 0 3 1
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