| Conditions | 8 |
| Paths | 108 |
| Total Lines | 52 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 30 |
| CRAP Score | 8.0021 |
| 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 |
||
| 8 | 8 | public static function generateMethodParameter(\ReflectionParameter $parameter) |
|
| 9 | { |
||
| 10 | try { |
||
| 11 | 8 | $allowsNull = $parameter->allowsNull(); |
|
| 12 | 8 | $defaultValue = null; |
|
| 13 | 8 | if ($allowsNull) { |
|
| 14 | 8 | $defaultValue = 'null'; |
|
| 15 | } else { |
||
| 16 | 8 | $defaultValue = var_export($parameter->getDefaultValue(), true); |
|
| 17 | } |
||
| 18 | |||
| 19 | 8 | if ($defaultValue) { |
|
| 20 | 8 | $defaultValue = "= $defaultValue"; |
|
| 21 | } |
||
| 22 | 8 | } catch (\ReflectionException $exception) { |
|
| 23 | 8 | $defaultValue = ''; |
|
| 24 | } |
||
| 25 | |||
| 26 | try { |
||
| 27 | 8 | $type = $parameter->getType(); |
|
| 28 | 8 | if ($type) { |
|
| 29 | 8 | $type = ' ' . self::getType($type) . ' '; |
|
| 30 | } else { |
||
| 31 | 8 | $type = ''; |
|
| 32 | } |
||
| 33 | |||
| 34 | 8 | $name = '$' . $parameter->getName(); |
|
|
|
|||
| 35 | |||
| 36 | // $canBePassByValue = $parameter->canBePassedByValue(); |
||
| 37 | 8 | $isPassedByReference = $parameter->isPassedByReference(); |
|
| 38 | 8 | $byReference = ''; |
|
| 39 | 8 | if ($isPassedByReference) { |
|
| 40 | 2 | $byReference = ' &'; |
|
| 41 | } |
||
| 42 | |||
| 43 | 8 | $isVariadic = $parameter->isVariadic(); |
|
| 44 | 8 | if ($isVariadic) { |
|
| 45 | 2 | $type = '...'; |
|
| 46 | 2 | $byReference = ''; |
|
| 47 | 8 | $defaultValue = ''; |
|
| 48 | } |
||
| 49 | } catch (\ReflectionException $e) { |
||
| 50 | } |
||
| 51 | |||
| 52 | 8 | return sprintf( |
|
| 53 | 8 | '%s%s%s%s', |
|
| 54 | 8 | $type, |
|
| 55 | 8 | $byReference, |
|
| 56 | 8 | $name, |
|
| 57 | 8 | $defaultValue |
|
| 58 | ); |
||
| 59 | } |
||
| 60 | |||
| 66 |