| Conditions | 11 |
| Paths | 12 |
| Total Lines | 34 |
| 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 |
||
| 18 | public static function handle($data, $parameters, $posts, $responsesFields, $ctrl) |
||
| 19 | { |
||
| 20 | $row = $data->first(); |
||
| 21 | |||
| 22 | if (! $row) { |
||
| 23 | return ApiResponder::makeResult(0, 'There is no data found !'); |
||
| 24 | } |
||
| 25 | |||
| 26 | foreach ($parameters as $param) { |
||
| 27 | $name = $param['name']; |
||
| 28 | $type = $param['type']; |
||
| 29 | $value = $posts[$name]; |
||
| 30 | $used = $param['used']; |
||
| 31 | $required = $param['required']; |
||
| 32 | |||
| 33 | if ($param['config'] != '' && substr($param['config'], 0, 1) != '*') { |
||
| 34 | $value = $param['config']; |
||
| 35 | } |
||
| 36 | if (Hash::check($value, $row->{$name})) { |
||
| 37 | continue; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($required && $type == 'password') { |
||
| 41 | self::passwordError($posts, $ctrl); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (! $required && $used && $value) { |
||
| 45 | self::passwordError($posts, $ctrl); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | self::handleFile($row, $responsesFields); |
||
| 50 | |||
| 51 | return self::success($row); |
||
| 52 | } |
||
| 93 | } |