Conditions | 14 |
Paths | 260 |
Total Lines | 67 |
Code Lines | 43 |
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 |
||
35 | protected function render() { |
||
36 | /** @var Interface_ $interface */ |
||
37 | $interface = $this->element; |
||
38 | |||
39 | $namespace = str_replace('\\' . $interface->getName(), '', $interface->getFqsen()); |
||
40 | |||
41 | $docBlock = $interface->getDocBlock(); |
||
42 | $this->addH1(self::escape($interface->getFqsen()))->addLine(); |
||
43 | if($namespace !== '') { |
||
44 | $this->beginPhpDomain('namespace', substr($namespace, 1), false); |
||
45 | } |
||
46 | $this->beginPhpDomain('interface', $interface->getName(), false); |
||
47 | |||
48 | $this->addLine(); |
||
49 | |||
50 | $this->callExtensions(self::SECTION_BEFORE_DESCRIPTION); |
||
51 | |||
52 | $this->addDocBlockDescription($docBlock); |
||
53 | |||
54 | // Add class details |
||
55 | $parents = ''; |
||
56 | foreach ($interface->getParents() as $parent) { |
||
57 | $parents .= $this->getLink('interface', $parent) . ' '; |
||
58 | } |
||
59 | $this->addFieldList('Parent', $parents)->addLine(); |
||
60 | |||
61 | $this->callExtensions(self::SECTION_AFTER_DESCRIPTION); |
||
62 | |||
63 | foreach ($interface->getMethods() as $method) { |
||
64 | /* Render method */ |
||
65 | $docBlock = $method->getDocBlock(); |
||
66 | $params = []; |
||
67 | if ($docBlock !== null) { |
||
68 | /** @var Param $param */ |
||
69 | foreach ($docBlock->getTagsByName('param') as $param) { |
||
70 | $params[$param->getVariableName()] = $param; |
||
|
|||
71 | } |
||
72 | } |
||
73 | $args = ''; |
||
74 | foreach ($method->getArguments() as $argument) { |
||
75 | $args .= '$' . $argument->getName() . ', '; |
||
76 | } |
||
77 | $args = substr($args, 0, -2); |
||
78 | $modifiers = $method->getVisibility(); |
||
79 | $modifiers .= $method->isAbstract() ? ' abstract' : ''; |
||
80 | $modifiers .= $method->isFinal() ? ' final' : ''; |
||
81 | $modifiers .= $method->isStatic() ? ' static' : ''; |
||
82 | $this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
||
83 | $this->indent(); |
||
84 | |||
85 | $this->beginPhpDomain('method', $method->getName() . '(' . $args . ')'); |
||
86 | $this->addLine(); |
||
87 | $this->addDocBlockDescription($docBlock); |
||
88 | |||
89 | if (!empty($params)) { |
||
90 | foreach ($method->getArguments() as $argument) { |
||
91 | /** @var Param $param */ |
||
92 | $param = $params[$argument->getName()]; |
||
93 | if ($param !== null) $this->addMultiline(':param ' . RstBuilder::escape($param->getType()) . ' $' . $argument->getName() . ': ' . RstBuilder::escape($param->getDescription()), true); |
||
94 | } |
||
95 | foreach ($docBlock->getTags() as $tag) { |
||
96 | $this->addDocblockTag($tag->getName(), $docBlock); |
||
97 | } |
||
98 | $this->addLine(); |
||
99 | } |
||
100 | $this->unindent(); |
||
101 | $this->endPhpDomain('method'); |
||
102 | } |
||
113 | } |