Completed
Push — master ( 852ed1...bbf814 )
by Armando
02:56 queued 12s
created

Action::isAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
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 NPM\TelegramBotManager;
12
13
class Action
14
{
15
    /**
16
     * @var array List of valid actions that can be called.
17
     */
18
    private static $valid_actions = [
19
        'set',
20
        'unset',
21
        'reset',
22
        'handle',
23
    ];
24
25
    /**
26
     * @var string Action to be executed.
27
     */
28
    private $action;
29
30
    /**
31
     * Action constructor.
32
     *
33
     * @param string $action
34
     *
35
     * @throws \InvalidArgumentException
36
     */
37
    public function __construct($action = 'handle')
38
    {
39
        $this->action = $action ?: 'handle';
40
41
        if (!$this->isAction(self::$valid_actions)) {
42
            throw new \InvalidArgumentException('Invalid action');
43
        }
44
    }
45
46
    /**
47
     * Check if the current action is one of the passed ones.
48
     *
49
     * @param string|array $actions
50
     *
51
     * @return bool
52
     */
53
    public function isAction($actions)
54
    {
55
        return in_array($this->action, (array)$actions, true);
56
    }
57
58
    /**
59
     * Return the current action.
60
     *
61
     * @return string
62
     */
63
    public function getAction()
64
    {
65
        return $this->action;
66
    }
67
}
68