Conditions | 10 |
Paths | 7 |
Total Lines | 22 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 convert(ResponseInterface $response, $requestFormat, $dataType) |
||
19 | { |
||
20 | if (($requestFormat === 'json' && $dataType === 'simple_xml') || |
||
21 | ($requestFormat === 'xml' && $dataType === 'array')) { |
||
22 | throw new \InvalidArgumentException(sprintf('Can not use reponse data format "%s" with the request format "s%"', $dataType, $requestFormat)); |
||
23 | } |
||
24 | |||
25 | switch ($dataType) { |
||
26 | case 'array': |
||
27 | return self::convertToArray($response); |
||
28 | case 'string': |
||
29 | return $response->getBody()->__toString(); |
||
30 | case 'simple_xml': |
||
31 | return self::convertToSimpleXml($response); |
||
32 | case 'stream': |
||
33 | return $response->getBody(); |
||
34 | case 'psr7': |
||
35 | return $response; |
||
36 | default: |
||
37 | throw new \InvalidArgumentException(sprintf('Format "%s" is not supported', $dataType)); |
||
38 | } |
||
39 | } |
||
40 | |||
75 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.