1 | <?php |
||
17 | class Module extends ControllerAbstract |
||
18 | { |
||
19 | /** |
||
20 | * process the class |
||
21 | * |
||
22 | * @since 4.0.0 |
||
23 | * |
||
24 | * @param string $action action to process |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | |||
29 | public function process(string $action = null) : string |
||
30 | { |
||
31 | $postArray = $this->_normalizePost($this->_sanitizePost()); |
||
32 | $validateArray = $this->_validatePost($postArray); |
||
|
|||
33 | |||
34 | /* validate post */ |
||
35 | |||
36 | if ($validateArray) |
||
37 | { |
||
38 | return $this->_error( |
||
39 | [ |
||
40 | 'route' => $this->_getErrorRoute($postArray), |
||
41 | 'message' => $validateArray |
||
42 | ]); |
||
43 | } |
||
44 | |||
45 | /* handle update */ |
||
46 | |||
47 | if ($action === 'update') |
||
48 | { |
||
49 | $updateArray = |
||
50 | [ |
||
51 | 'name' => $postArray['name'], |
||
52 | 'description' => $postArray['description'], |
||
53 | 'status' => $postArray['status'], |
||
54 | 'access' => $postArray['access'] |
||
55 | ]; |
||
56 | if ($this->_update($postArray['id'], $updateArray)) |
||
57 | { |
||
58 | return $this->_success( |
||
59 | [ |
||
60 | 'route' => $this->_getSuccessRoute($postArray), |
||
61 | 'timeout' => 2 |
||
62 | ]); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /* handle error */ |
||
67 | |||
68 | return $this->_error( |
||
69 | [ |
||
70 | 'route' => $this->_getErrorRoute($postArray) |
||
71 | ]); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * sanitize the post |
||
76 | * |
||
77 | * @since 4.0.0 |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | |||
82 | protected function _sanitizePost() : array |
||
97 | |||
98 | /** |
||
99 | * validate the post |
||
100 | * |
||
101 | * @since 4.0.0 |
||
102 | * |
||
103 | * @param array $postArray array of the post |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | |||
108 | protected function _validatePost(array $postArray = []) : array |
||
120 | |||
121 | /** |
||
122 | * update the module |
||
123 | * |
||
124 | * @since 4.0.0 |
||
125 | * |
||
126 | * @param int $moduleId identifier of the module |
||
127 | * @param array $updateArray array of the update |
||
128 | * |
||
129 | * @return bool |
||
130 | */ |
||
131 | |||
132 | public function _update(int $moduleId = null, array $updateArray = []) : bool |
||
137 | |||
138 | /** |
||
139 | * get success route |
||
140 | * |
||
141 | * @since 4.0.0 |
||
142 | * |
||
143 | * @param array $postArray array of the post |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | |||
148 | protected function _getSuccessRoute(array $postArray = []) : string |
||
156 | |||
157 | /** |
||
158 | * get error route |
||
159 | * |
||
160 | * @since 4.0.0 |
||
161 | * |
||
162 | * @param array $postArray array of the post |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | |||
167 | protected function _getErrorRoute(array $postArray = []) : string |
||
179 | } |
||
180 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.