Conditions | 28 |
Paths | 3073 |
Total Lines | 111 |
Code Lines | 68 |
Lines | 7 |
Ratio | 6.31 % |
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 |
||
32 | protected function render() { |
||
33 | |||
34 | /** @var Class_ $class */ |
||
35 | $class = $this->element; |
||
36 | |||
37 | if (!$this->shouldRenderElement($class)) { |
||
38 | return; |
||
39 | } |
||
40 | |||
41 | $docBlock = $class->getDocBlock(); |
||
42 | |||
43 | $this->addH1(self::escape($class->getName())); |
||
44 | |||
45 | $namespace = substr($class->getFqsen(), 0, strlen($class->getFqsen())-strlen('\\' . $class->getName())); |
||
46 | if($namespace !== '') { |
||
47 | $this->beginPhpDomain('namespace', substr($namespace, 1), false); |
||
48 | } |
||
49 | |||
50 | $modifiers = $class->isAbstract() ? ' abstract' : ''; |
||
51 | $modifiers = $class->isFinal() ? ' final' : $modifiers; |
||
52 | if ($modifiers !== '') { |
||
53 | $this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
||
54 | } |
||
55 | $this->beginPhpDomain('class', $class->getName(), false); |
||
56 | |||
57 | $this->indent(); |
||
58 | $this->addDocBlockDescription($docBlock); |
||
59 | |||
60 | if($class instanceof Class_) { |
||
61 | // Add class details |
||
62 | $parent = $class->getParent(); |
||
63 | if ($parent !== null) { |
||
64 | $this->addFieldList('Extends', $parent !== null ? $this->getLink('class', $parent) : ''); |
||
65 | } |
||
66 | } |
||
67 | $implementedInterfaces = ''; |
||
68 | foreach ($class->getInterfaces() as $int) { |
||
69 | $implementedInterfaces .= $this->getLink('interface', $int) . ' '; |
||
70 | } |
||
71 | if ($implementedInterfaces !== '') { |
||
72 | $this->addFieldList('Implements', $implementedInterfaces); |
||
73 | } |
||
74 | |||
75 | $usedTraits = ''; |
||
76 | foreach ($class->getUsedTraits() as $trait) { |
||
77 | $usedTraits .= $this->getLink('trait', $trait) . ' '; |
||
78 | } |
||
79 | if ($usedTraits !== '') { |
||
80 | $this->addFieldList('Used traits', $usedTraits); |
||
81 | } |
||
82 | |||
83 | $this->unindent(); |
||
84 | $this->addLine(); |
||
85 | $this->addLine(); |
||
86 | |||
87 | // Add class constants |
||
88 | if (count($class->getConstants()) > 0) { |
||
89 | $this->addH2('Constants'); |
||
90 | foreach ($class->getConstants() as $constant) { |
||
91 | if ($this->shouldRenderElement($constant)) { |
||
92 | $this->addConstant($constant); |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | $this->addProperties($class->getProperties()); |
||
98 | |||
99 | if (count($class->getMethods()) > 0) { |
||
100 | $this->addH2('Methods'); |
||
101 | /* Render methods of a class */ |
||
102 | foreach ($class->getMethods() as $method) { |
||
103 | if (!$this->shouldRenderElement($method)) { |
||
104 | continue; |
||
105 | } |
||
106 | $docBlock = $method->getDocBlock(); |
||
107 | $params = []; |
||
108 | if ($docBlock !== null) { |
||
109 | /** @var Param $param */ |
||
110 | foreach ($docBlock->getTagsByName('param') as $param) { |
||
111 | $params[$param->getVariableName()] = $param; |
||
1 ignored issue
–
show
|
|||
112 | } |
||
113 | } |
||
114 | $args = ''; |
||
115 | /** @var Argument $argument */ |
||
116 | foreach ($method->getArguments() as $argument) { |
||
117 | // TODO: defaults, types |
||
118 | $args .= ' $' . $argument->getName() . ', '; |
||
119 | } |
||
120 | $args = substr($args, 0, -2); |
||
121 | |||
122 | $modifiers = $method->getVisibility(); |
||
123 | $modifiers .= $method->isAbstract() ? ' abstract' : ''; |
||
124 | $modifiers .= $method->isFinal() ? ' final' : ''; |
||
125 | $modifiers .= $method->isStatic() ? ' static' : ''; |
||
126 | $this->addLine('.. rst-class:: ' . $modifiers)->addLine(); |
||
127 | $this->indent(); |
||
128 | $this->beginPhpDomain('method', $method->getName() . '(' . $args . ')'); |
||
129 | $this->addDocBlockDescription($docBlock); |
||
130 | $this->addLine(); |
||
131 | View Code Duplication | if (!empty($params)) { |
|
132 | foreach ($method->getArguments() as $argument) { |
||
133 | /** @var Param $param */ |
||
134 | $param = $params[$argument->getName()]; |
||
135 | if ($param !== null) $this->addMultiline(':param ' . self::escape($param->getType()) . ' $' . $argument->getName() . ': ' . $param->getDescription(), true); |
||
136 | } |
||
137 | } |
||
138 | $this->endPhpDomain('method'); |
||
139 | $this->unindent(); |
||
140 | } |
||
141 | } |
||
142 | $this->endPhpDomain(); //class |
||
143 | } |
||
145 | } |