Conditions | 18 |
Paths | 433 |
Total Lines | 74 |
Code Lines | 40 |
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 |
||
99 | protected function renderMethod(MethodObject $o) |
||
100 | { |
||
101 | if (!empty(self::$method_cache[$o->owner_class][$o->name])) { |
||
102 | $children = self::$method_cache[$o->owner_class][$o->name]['children']; |
||
103 | |||
104 | $header = $this->renderer->renderHeaderWrapper( |
||
105 | $o, |
||
106 | (bool) \strlen($children), |
||
107 | self::$method_cache[$o->owner_class][$o->name]['header'] |
||
108 | ); |
||
109 | |||
110 | return '<dl>'.$header.$children.'</dl>'; |
||
111 | } |
||
112 | |||
113 | $children = $this->renderer->renderChildren($o); |
||
114 | |||
115 | $header = ''; |
||
116 | |||
117 | if (null !== ($s = $o->getModifiers()) || $o->return_reference) { |
||
118 | $header .= '<var>'.$s; |
||
119 | |||
120 | if ($o->return_reference) { |
||
121 | if ($s) { |
||
122 | $header .= ' '; |
||
123 | } |
||
124 | $header .= $this->renderer->escape('&'); |
||
125 | } |
||
126 | |||
127 | $header .= '</var> '; |
||
128 | } |
||
129 | |||
130 | if (null !== ($s = $o->getName())) { |
||
131 | $function = $this->renderer->escape($s).'('.$this->renderer->escape($o->getParams()).')'; |
||
132 | |||
133 | if (null !== ($url = $o->getPhpDocUrl())) { |
||
134 | $function = '<a href="'.$url.'" target=_blank>'.$function.'</a>'; |
||
135 | } |
||
136 | |||
137 | $header .= '<dfn>'.$function.'</dfn>'; |
||
138 | } |
||
139 | |||
140 | if (!empty($o->returntype)) { |
||
141 | $header .= ': <var>'; |
||
142 | |||
143 | if ($o->return_reference) { |
||
144 | $header .= $this->renderer->escape('&'); |
||
145 | } |
||
146 | |||
147 | $header .= $this->renderer->escape($o->returntype).'</var>'; |
||
148 | } elseif ($o->docstring) { |
||
149 | if (\preg_match('/@return\\s+(.*)\\r?\\n/m', $o->docstring, $matches)) { |
||
150 | if (\trim($matches[1])) { |
||
151 | $header .= ': <var>'.$this->renderer->escape(\trim($matches[1])).'</var>'; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | if (null !== ($s = $o->getValueShort())) { |
||
157 | if (RichRenderer::$strlen_max && BlobObject::strlen($s) > RichRenderer::$strlen_max) { |
||
158 | $s = \substr($s, 0, RichRenderer::$strlen_max).'...'; |
||
159 | } |
||
160 | $header .= ' '.$this->renderer->escape($s); |
||
161 | } |
||
162 | |||
163 | if (\strlen($o->owner_class) && \strlen($o->name)) { |
||
164 | self::$method_cache[$o->owner_class][$o->name] = array( |
||
165 | 'header' => $header, |
||
166 | 'children' => $children, |
||
167 | ); |
||
168 | } |
||
169 | |||
170 | $header = $this->renderer->renderHeaderWrapper($o, (bool) \strlen($children), $header); |
||
171 | |||
172 | return '<dl>'.$header.$children.'</dl>'; |
||
173 | } |
||
175 |