Conditions | 13 |
Paths | 13 |
Total Lines | 51 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
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 |
||
16 | public function getParamDocBlockHint(array $docBlockParams, \ReflectionParameter $param, array $arguments = []) |
||
17 | { |
||
18 | $typeHint = false; |
||
19 | |||
20 | /** @var DocBlock\Tag\ParamTag $docBlockParam */ |
||
21 | foreach ($docBlockParams as $docBlockParam) { |
||
22 | |||
23 | if (!($docBlockParam instanceof DocBlock\Tag\ParamTag)) { |
||
24 | continue; |
||
25 | } |
||
26 | |||
27 | $type = $docBlockParam->getType(); |
||
28 | $docBlockParamName = $docBlockParam->getVariableName(); |
||
29 | |||
30 | if (($param->getName() === ltrim($docBlockParamName, '$')) |
||
31 | && (!empty($type)) |
||
32 | ) { |
||
33 | $definitions = explode('|', $type); |
||
34 | |||
35 | foreach ($arguments as $key => $argument) { |
||
36 | |||
37 | foreach ($definitions as $definition) { |
||
38 | |||
39 | if (is_object($argument) |
||
40 | && in_array(ltrim($definition, '\\'), $this->getImplemented(get_class($argument))) |
||
41 | && (is_numeric($key) || (ltrim($docBlockParamName, '$') === $key) |
||
42 | )) { |
||
43 | $typeHint = $definition; |
||
44 | |||
45 | // no need to loop again, since we found a match already! |
||
46 | continue 3; |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | |||
51 | if ($typeHint === false) { |
||
52 | |||
53 | // use first definition, there is no way to know which instance of the hinted doc block definitions is actually required |
||
54 | // because there were either no arguments given or no argument match was found |
||
55 | list($firstDefinition,) = $definitions; |
||
56 | |||
57 | if (!in_array(strtolower($firstDefinition), ['int', 'float', 'bool', 'string', 'array', 'null', 'mixed'])) { |
||
58 | |||
59 | $typeHint = $firstDefinition; |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | return $typeHint; |
||
66 | } |
||
67 | |||
78 |