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 | } |
||
114 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.