| Conditions | 14 |
| Paths | 30 |
| Total Lines | 44 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 210 |
| 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 |
||
| 56 | public static function fromReflection(\ReflectionParameter $ref) { |
||
| 57 | $parameter = new static(); |
||
| 58 | $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference()); |
||
| 59 | |||
| 60 | if ($ref->isDefaultValueAvailable()) { |
||
| 61 | $value = $ref->getDefaultValue(); |
||
| 62 | |||
| 63 | if (is_string($value) |
||
| 64 | || is_int($value) |
||
| 65 | || is_float($value) |
||
| 66 | || is_bool($value) |
||
| 67 | || is_null($value) |
||
| 68 | || ($value instanceof PhpConstant)) { |
||
| 69 | $parameter->setValue($value); |
||
| 70 | } else { |
||
| 71 | $parameter->setExpression($value); |
||
|
1 ignored issue
–
show
|
|||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // find type and description in docblock |
||
| 76 | $docblock = new Docblock($ref->getDeclaringFunction()); |
||
| 77 | |||
| 78 | $params = $docblock->getTags('param'); |
||
| 79 | $tag = $params->find($ref->name, function (ParamTag $t, $name) { |
||
| 80 | return $t->getVariable() == '$' . $name; |
||
| 81 | }); |
||
| 82 | |||
| 83 | if ($tag !== null) { |
||
| 84 | $parameter->setType($tag->getType(), $tag->getDescription()); |
||
| 85 | } |
||
| 86 | |||
| 87 | // set type if not found in comment |
||
| 88 | if ($parameter->getType() === null) { |
||
| 89 | if ($ref->isArray()) { |
||
| 90 | $parameter->setType('array'); |
||
| 91 | } elseif ($class = $ref->getClass()) { |
||
| 92 | $parameter->setType($class->getName()); |
||
| 93 | } elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) { |
||
| 94 | $parameter->setType('callable'); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | return $parameter; |
||
| 99 | } |
||
| 100 | |||
| 164 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: