Conditions | 12 |
Paths | 21 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 2 | Features | 1 |
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 |
||
40 | public function render($type, &$builder, $element) |
||
41 | { |
||
42 | if ($type === PhpDomainBuilder::SECTION_AFTER_INTRODUCTION) { |
||
43 | if ($element instanceof Class_ || $element instanceof Interface_ || $element instanceof Trait_) { |
||
44 | $builder->addLine(); |
||
45 | $builder->addH2('Summary'); |
||
46 | |||
47 | /** @var Interface_ $interface */ |
||
48 | $interface = $builder->getElement(); |
||
49 | |||
50 | if (count($interface->getMethods()) > 0) { |
||
51 | $builder->addH3('Methods'); |
||
52 | foreach ($interface->getMethods() as $method) { |
||
53 | //We don't want add an no displayed method to Summary |
||
54 | if (!$builder->shouldRenderElement($method)) { |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | $args = ''; |
||
59 | /** @var Argument $argument */ |
||
60 | foreach ($method->getArguments() as $argument) { |
||
61 | // TODO: defaults, types |
||
62 | $args .= '$'.$argument->getName().', '; |
||
63 | } |
||
64 | $args = substr($args, 0, -2); |
||
65 | $modifiers = $method->getVisibility(); |
||
66 | $modifiers .= $method->isAbstract() ? ' abstract' : ''; |
||
67 | $modifiers .= $method->isFinal() ? ' final' : ''; |
||
68 | $modifiers .= $method->isStatic() ? ' static' : ''; |
||
69 | $signature = $modifiers.' '.$method->getName().'('.$args.')'; |
||
70 | |||
71 | $builder->addLine('* '.PhpDomainBuilder::getLink('meth', $method->getFqsen(), $signature)); |
||
72 | } |
||
73 | $builder->addLine()->addLine(); |
||
74 | } |
||
79 |