Total Complexity | 14 |
Total Lines | 84 |
Duplicated Lines | 0 % |
Coverage | 85.71% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php /** @noinspection PhpDocMissingThrowsInspection */ |
||
9 | trait HasActionTrait |
||
10 | { |
||
11 | protected $action = null; |
||
12 | |||
13 | /** |
||
14 | * @return mixed |
||
15 | */ |
||
16 | 7 | public function getAction() |
|
17 | { |
||
18 | 7 | return $this->action; |
|
19 | } |
||
20 | |||
21 | /** |
||
22 | * @param mixed $action |
||
23 | */ |
||
24 | 3 | public function setAction($action) |
|
27 | 3 | } |
|
28 | |||
29 | /** |
||
30 | * @return bool |
||
31 | */ |
||
32 | 5 | public function hasAction() |
|
33 | { |
||
34 | 5 | if ($this->action === null) { |
|
35 | 5 | return false; |
|
36 | } |
||
37 | if (is_array($this->action)) { |
||
38 | if (!isset($this->action['action'])) { |
||
39 | return false; |
||
40 | } |
||
41 | } |
||
42 | return true; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param $name |
||
47 | * @param $value |
||
48 | * @return void |
||
49 | */ |
||
50 | 5 | public function setActionParam($name, $value) |
|
51 | { |
||
52 | /** @noinspection PhpUnhandledExceptionInspection */ |
||
53 | 5 | $this->guardActionAsArray(); |
|
54 | |||
55 | 4 | $this->action[$name] = $value; |
|
56 | 4 | } |
|
57 | |||
58 | /** |
||
59 | * @param $name |
||
60 | * @param $value |
||
61 | * @return mixed |
||
62 | * @throws \Exception |
||
63 | */ |
||
64 | 6 | public function getActionParam($name) |
|
65 | { |
||
66 | 6 | $this->guardActionAsArray(); |
|
67 | |||
68 | 5 | return isset($this->action[$name]) ? $this->action[$name] : null; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * @throws \Exception |
||
73 | */ |
||
74 | 7 | protected function guardActionAsArray() |
|
75 | { |
||
76 | 7 | if (!is_array($this->action) && $this->action !== null) { |
|
77 | 2 | throw new \Exception( |
|
78 | 2 | "Command Action is not an array, [" . print_r($this->action, true) . "]" |
|
79 | ); |
||
80 | } |
||
81 | 5 | } |
|
82 | |||
83 | /** |
||
84 | * @param $name |
||
85 | * @return boolean |
||
86 | */ |
||
87 | 4 | public function hasActionParam($name) |
|
93 | } |
||
94 | } |
||
95 |