Conditions | 15 |
Paths | 56 |
Total Lines | 44 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
62 | private function createArgumentDescriptorForMagicMethod($argument) |
||
63 | { |
||
64 | $argumentType = null; |
||
65 | $argumentName = null; |
||
66 | $argumentDefault = false; // false means we have not encountered the '=' yet. |
||
67 | foreach ($argument as $part) { |
||
68 | $part = trim($part); |
||
69 | if (!$part) { |
||
70 | continue; |
||
71 | } |
||
72 | |||
73 | // Type should not be assigned after name |
||
74 | if (!$argumentName && !$argumentType && $part{0} != '$') { |
||
75 | $argumentType = $part; |
||
76 | } elseif (!$argumentName && $part{0} == '$') { |
||
77 | $argumentName = $part; |
||
78 | } elseif ($part == '=') { |
||
79 | $argumentDefault = null; |
||
80 | } elseif ($argumentDefault === null) { |
||
81 | $argumentDefault = $part; |
||
82 | } |
||
83 | } |
||
84 | if ($argumentDefault === false) { |
||
85 | $argumentDefault = null; |
||
86 | } |
||
87 | |||
88 | // if no name is set but a type is then the input is malformed and we correct for it |
||
89 | if ($argumentType && !$argumentName) { |
||
90 | $argumentName = $argumentType; |
||
91 | $argumentType = null; |
||
92 | } |
||
93 | |||
94 | // if there is no type then we assume it is 'mixed' |
||
95 | if (!$argumentType) { |
||
96 | $argumentType = 'mixed'; |
||
97 | } |
||
98 | |||
99 | $argumentDescriptor = new ArgumentDescriptor(); |
||
100 | $argumentDescriptor->setTypes($this->builder->buildDescriptor(new Collection(array($argumentType)))); |
||
101 | $argumentDescriptor->setName($argumentName[0] == '$' ? $argumentName : '$' . $argumentName); |
||
102 | $argumentDescriptor->setDefault($argumentDefault); |
||
103 | |||
104 | return $argumentDescriptor; |
||
105 | } |
||
106 | } |
||
107 |
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: