Conditions | 10 |
Paths | 10 |
Total Lines | 25 |
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 |
||
72 | private function getJsonErrorMessage($errorCode) |
||
73 | { |
||
74 | switch ($errorCode) { |
||
75 | case JSON_ERROR_NONE: |
||
76 | return 'JSON_ERROR_NONE'; |
||
77 | case JSON_ERROR_DEPTH: |
||
78 | return 'JSON_ERROR_DEPTH'; |
||
79 | case JSON_ERROR_STATE_MISMATCH: |
||
80 | return 'JSON_ERROR_STATE_MISMATCH'; |
||
81 | case JSON_ERROR_CTRL_CHAR: |
||
82 | return 'JSON_ERROR_CTRL_CHAR'; |
||
83 | case JSON_ERROR_SYNTAX: |
||
84 | return 'JSON_ERROR_SYNTAX'; |
||
85 | case JSON_ERROR_UTF8: |
||
86 | return 'JSON_ERROR_UTF8'; |
||
87 | case constant('JSON_ERROR_RECURSION'): |
||
88 | return 'JSON_ERROR_RECURSION'; |
||
89 | case constant('JSON_ERROR_INF_OR_NAN'): |
||
90 | return 'JSON_ERROR_INF_OR_NAN'; |
||
91 | case constant('JSON_ERROR_UNSUPPORTED_TYPE'): |
||
92 | return 'JSON_ERROR_UNSUPPORTED_TYPE'; |
||
93 | default: |
||
94 | throw new LogicException(sprintf('Unknown JSON decoding error code %d encountered', $errorCode)); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 |
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.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.