Conditions | 16 |
Paths | 2064 |
Total Lines | 79 |
Code Lines | 51 |
Lines | 39 |
Ratio | 49.37 % |
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 |
||
33 | protected function render() { |
||
34 | /** @var Trait_ $trait */ |
||
35 | $trait = $this->element; |
||
36 | |||
37 | $docBlock = $trait->getDocBlock(); |
||
38 | |||
39 | $this->addH1(self::escape($trait->getFqsen())); |
||
40 | |||
41 | $namespace = str_replace('\\' . $trait->getName(), '', $trait->getFqsen()); |
||
42 | if($namespace !== '') { |
||
43 | $this->beginPhpDomain('namespace', substr($namespace, 1), false); |
||
44 | } |
||
45 | |||
46 | $this->beginPhpDomain('trait', $trait->getName(), false); |
||
47 | |||
48 | $this->indent(); |
||
49 | if ($docBlock) { |
||
50 | $this |
||
51 | ->addLine($docBlock->getDescription()) |
||
52 | ->addLine(); |
||
53 | } |
||
54 | |||
55 | $usedTraits = ''; |
||
56 | foreach ($trait->getUsedTraits() as $trait) { |
||
57 | $usedTraits .= $this->getLink('trait', $trait) . ' '; |
||
58 | } |
||
59 | $this->addFieldList('Traits', $usedTraits); |
||
60 | |||
61 | $this->unindent(); |
||
62 | $this->addLine(); |
||
63 | $this->addLine(); |
||
64 | |||
65 | $this->addH2('Properties'); |
||
66 | foreach ($trait->getProperties() as $property) { |
||
|
|||
67 | $this->addProperty($property); |
||
68 | } |
||
69 | |||
70 | $this->addH2('Methods'); |
||
71 | /* Render methods of a trait */ |
||
72 | View Code Duplication | foreach ($trait->getMethods() as $method) { |
|
73 | $docBlock = $method->getDocBlock(); |
||
74 | $params = []; |
||
75 | if($docBlock !== null) { |
||
76 | /** @var Param $param */ |
||
77 | foreach ($docBlock->getTagsByName('param') as $param) { |
||
78 | $params[$param->getVariableName()] = $param; |
||
1 ignored issue
–
show
|
|||
79 | } |
||
80 | } |
||
81 | $args = ''; |
||
82 | /** @var Argument $argument */ |
||
83 | foreach ($method->getArguments() as $argument) { |
||
84 | // TODO: defaults, types |
||
85 | $args .= ' $' . $argument->getName() . ', '; |
||
86 | } |
||
87 | $args = substr($args, 0, -2); |
||
88 | |||
89 | $modifiers = $method->getVisibility(); |
||
90 | $modifiers .= $method->isAbstract() ? ' abstract' : ''; |
||
91 | $modifiers .= $method->isFinal() ? ' final' : ''; |
||
92 | $modifiers .= $method->isStatic() ? ' static' : ''; |
||
93 | $this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
||
94 | $this->indent(); |
||
95 | $this->beginPhpDomain('method', $method->getName().'('.$args.')'); |
||
96 | if ($docBlock) |
||
97 | $this->addMultiline($docBlock->getDescription()); |
||
98 | $this->addLine(); |
||
99 | if (!empty($params)) { |
||
100 | foreach ($method->getArguments() as $argument) { |
||
101 | /** @var Param $param */ |
||
102 | $param = $params[$argument->getName()]; |
||
103 | if ($param !== null) |
||
104 | $this->addMultiline(':param ' . $param->getType() . ' $' . $argument->getName() . ': ' . $param->getDescription(), true); |
||
105 | } |
||
106 | } |
||
107 | $this->endPhpDomain('method'); |
||
108 | $this->unindent(); |
||
109 | |||
110 | } |
||
111 | $this->endPhpDomain(); //trait |
||
112 | } |
||
114 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.