Conditions | 11 |
Paths | 20 |
Total Lines | 29 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
46 | public function render($type, &$builder, $element) { |
||
47 | if ($type === PhpDomainBuilder::SECTION_AFTER_INTRODUCTION) { |
||
48 | if ($element instanceof Class_ || $element instanceof Interface_ || $element instanceof Trait_) { |
||
49 | $builder->addLine(); |
||
50 | $builder->addH2('Summary'); |
||
51 | |||
52 | /** @var Interface_ $interface */ |
||
53 | $interface = $builder->getElement(); |
||
54 | |||
55 | if(count($interface->getMethods()) > 0) { |
||
56 | $builder->addH3('Methods'); |
||
57 | foreach ($interface->getMethods() as $method) { |
||
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 | } |
||
74 | $builder->addLine()->addLine(); |
||
75 | } |
||
80 | } |