| Conditions | 12 |
| Paths | 9 |
| Total Lines | 26 |
| Code Lines | 18 |
| 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 |
||
| 125 | public static function validate($key, $value) |
||
| 126 | { |
||
| 127 | switch ($key) { |
||
| 128 | case 'id': |
||
| 129 | if (! EBB\isValidID($value)) { |
||
| 130 | throw new InvalidArgumentException(__('Invalid district ID.')); |
||
| 131 | } |
||
| 132 | break; |
||
| 133 | case 'name': |
||
| 134 | if (! is_string($value) || empty($value)) { |
||
| 135 | throw new InvalidArgumentException(__('Invalid district name.')); |
||
| 136 | } |
||
| 137 | break; |
||
| 138 | case 'city': |
||
| 139 | if (! $value instanceof City || ! $value->isExists()) { |
||
| 140 | throw new InvalidArgumentException(__('Invalid district city.')); |
||
| 141 | } |
||
| 142 | break; |
||
| 143 | case 'created_by': |
||
| 144 | if (! $value instanceof User || ! $value->isExists()) { |
||
| 145 | throw new InvalidArgumentException(__('Invalid district originator.')); |
||
| 146 | } |
||
| 147 | break; |
||
| 148 | } |
||
| 149 | |||
| 150 | return true; |
||
| 151 | } |
||
| 153 |