| Conditions | 10 |
| Paths | 7 |
| Total Lines | 22 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 23 | public static function convert(ResponseInterface $response, $requestFormat, $dataType) |
||
| 24 | { |
||
| 25 | if (($requestFormat === 'json' && $dataType === 'simple_xml') || |
||
| 26 | ($requestFormat === 'xml' && $dataType === 'array')) { |
||
| 27 | throw new InvalidArgumentException('Can not use reponse data format "%s" with the request format "%s".', $dataType, $requestFormat); |
||
| 28 | } |
||
| 29 | |||
| 30 | switch ($dataType) { |
||
| 31 | case 'array': |
||
| 32 | return self::convertToArray($response); |
||
| 33 | case 'string': |
||
| 34 | return $response->getBody()->__toString(); |
||
| 35 | case 'simple_xml': |
||
| 36 | return self::convertToSimpleXml($response); |
||
| 37 | case 'stream': |
||
| 38 | return $response->getBody(); |
||
| 39 | case 'psr7': |
||
| 40 | return $response; |
||
| 41 | default: |
||
| 42 | throw new InvalidArgumentException('Format "%s" is not supported', $dataType); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 73 |
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
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.