Conditions | 14 |
Paths | 30 |
Total Lines | 44 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Tests | 24 |
CRAP Score | 14.5719 |
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 | 2 | public static function fromReflection(\ReflectionParameter $ref) { |
|
57 | 2 | $parameter = new static(); |
|
58 | 2 | $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference()); |
|
59 | |||
60 | 2 | if ($ref->isDefaultValueAvailable()) { |
|
61 | 2 | $value = $ref->getDefaultValue(); |
|
62 | |||
63 | 2 | if (is_string($value) |
|
64 | 1 | || is_int($value) |
|
65 | 1 | || is_float($value) |
|
66 | 1 | || is_bool($value) |
|
67 | 1 | || is_null($value) |
|
68 | 2 | || ($value instanceof PhpConstant)) { |
|
69 | 2 | $parameter->setValue($value); |
|
70 | } else { |
||
71 | $parameter->setExpression($value); |
||
1 ignored issue
–
show
|
|||
72 | } |
||
73 | } |
||
74 | |||
75 | // find type and description in docblock |
||
76 | 2 | $docblock = new Docblock($ref->getDeclaringFunction()); |
|
77 | |||
78 | 2 | $params = $docblock->getTags('param'); |
|
79 | 2 | $tag = $params->find($ref->name, function (ParamTag $t, $name) { |
|
80 | 2 | return $t->getVariable() == '$' . $name; |
|
81 | 2 | }); |
|
82 | |||
83 | 2 | if ($tag !== null) { |
|
84 | 2 | $parameter->setType($tag->getType(), $tag->getDescription()); |
|
85 | } |
||
86 | |||
87 | // set type if not found in comment |
||
88 | 2 | if ($parameter->getType() === null) { |
|
89 | 1 | if ($ref->isArray()) { |
|
90 | $parameter->setType('array'); |
||
91 | 1 | } elseif ($class = $ref->getClass()) { |
|
92 | $parameter->setType($class->getName()); |
||
93 | 1 | } elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) { |
|
94 | $parameter->setType('callable'); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | 2 | 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: