| Conditions | 16 |
| Paths | 13 |
| Total Lines | 36 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 184 | public static function validate($key, $value) |
||
| 185 | { |
||
| 186 | switch ($key) { |
||
| 187 | case 'id': |
||
| 188 | if (! EBB\isValidID($value)) { |
||
| 189 | throw new InvalidArgumentException(__('Invalid user ID.')); |
||
| 190 | } |
||
| 191 | break; |
||
| 192 | case 'name': |
||
| 193 | if (! is_string($value) || empty($value)) { |
||
| 194 | throw new InvalidArgumentException(__('Invalid user name.')); |
||
| 195 | } |
||
| 196 | break; |
||
| 197 | case 'email': |
||
| 198 | if (! EBB\isValidEmail($value)) { |
||
| 199 | throw new InvalidArgumentException(__('Invalid user e-mail.')); |
||
| 200 | } |
||
| 201 | break; |
||
| 202 | case 'pass': |
||
| 203 | if (! is_string($value) || empty($value)) { |
||
| 204 | throw new InvalidArgumentException(__('Invalid user password.')); |
||
| 205 | } |
||
| 206 | break; |
||
| 207 | case 'role': |
||
| 208 | if (! is_string($value)) { |
||
| 209 | throw new InvalidArgumentException(__('Invalid user role.')); |
||
| 210 | } |
||
| 211 | break; |
||
| 212 | case 'status': |
||
| 213 | if (! is_string($value) || empty($value)) { |
||
| 214 | throw new InvalidArgumentException(__('Invalid user status.')); |
||
| 215 | } |
||
| 216 | break; |
||
| 217 | } |
||
| 218 | |||
| 219 | return true; |
||
| 220 | } |
||
| 222 |