| Conditions | 12 |
| Paths | 6 |
| Total Lines | 21 |
| Code Lines | 13 |
| 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 |
||
| 41 | protected function parseValue($value, $validation) |
||
| 42 | { |
||
| 43 | if (is_array($value) && !empty($value)) { |
||
| 44 | $valueArray = array(); |
||
| 45 | foreach ($value as $subKey => $subValue) { |
||
| 46 | if (is_object($subValue) && $subValue instanceof AbstractModel) { |
||
| 47 | $valueArray[Str::toSnakeCase($subKey)] = $subValue->export($validation); |
||
| 48 | } else { |
||
| 49 | $valueArray[Str::toSnakeCase($subKey)] = $subValue; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | return $valueArray; |
||
| 53 | } |
||
| 54 | if (is_object($value) && $value instanceof AbstractModel && !empty($value)) { |
||
| 55 | return $value->export(); |
||
| 56 | } |
||
| 57 | if (is_object($value) && $value instanceof \DateTime && !empty($value)) { |
||
| 58 | return $value->format('Y-m-d\Th:i:s'); |
||
| 59 | } |
||
| 60 | |||
| 61 | return $value; |
||
| 62 | } |
||
| 139 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: