| Conditions | 8 |
| Paths | 7 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 97 | function render($mode, Doku_Renderer $renderer, $data) { |
||
| 98 | global $lang; |
||
| 99 | |||
| 100 | if ($mode == 'xhtml') { |
||
| 101 | $renderer->info['cache'] = false; |
||
| 102 | |||
| 103 | @require_once(DOKU_INC.'inc/fulltext.php'); |
||
| 104 | $backlinks = ft_backlinks($data[0]); |
||
| 105 | |||
| 106 | dbglog($backlinks, "backlinks: all backlinks to: $data[0]"); |
||
| 107 | |||
| 108 | $renderer->doc .= '<div id="plugin__backlinks">'.DW_LF; |
||
| 109 | |||
| 110 | $filterNS = $data[1]; |
||
| 111 | if (!empty($backlinks) && !empty($filterNS)) { |
||
| 112 | if (stripos($filterNS, "!", 0) === 0) { |
||
| 113 | $filterNS = substr($filterNS, 1); |
||
| 114 | dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS"); |
||
| 115 | $backlinks = array_filter($backlinks, function($ns) use($filterNS) { |
||
| 116 | return stripos($ns, $filterNS, 0) !== 0; |
||
| 117 | }); |
||
| 118 | } else { |
||
| 119 | dbglog($filterNS, "backlinks: including namespace: $filterNS only"); |
||
| 120 | $backlinks = array_filter($backlinks, function($ns) use($filterNS) { |
||
| 121 | return stripos($ns, $filterNS, 0) === 0; |
||
| 122 | }); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | dbglog($backlinks, "backlinks: all backlinks to be rendered"); |
||
| 127 | |||
| 128 | if (!empty($backlinks)) { |
||
| 129 | |||
| 130 | $renderer->doc .= '<ul class="idx">'; |
||
| 131 | |||
| 132 | foreach ($backlinks as $backlink) { |
||
| 133 | $name = p_get_metadata($backlink, 'title'); |
||
| 134 | if (empty($name)) { |
||
| 135 | $name = $backlink; |
||
| 136 | } |
||
| 137 | $renderer->doc .= '<li><div class="li">'; |
||
| 138 | $renderer->doc .= html_wikilink(':'.$backlink, $name); |
||
| 139 | $renderer->doc .= '</div></li>'.DW_LF; |
||
| 140 | } |
||
| 141 | |||
| 142 | $renderer->doc .= '</ul>'.DW_LF; |
||
| 143 | } else { |
||
| 144 | $renderer->doc .= "<strong>Plugin Backlinks: ".$lang['nothingfound']."</strong>".DW_LF; |
||
| 145 | } |
||
| 146 | |||
| 147 | $renderer->doc .= '</div>'.DW_LF; |
||
| 148 | |||
| 149 | return true; |
||
| 150 | } |
||
| 151 | return false; |
||
| 152 | } |
||
| 153 | } |
||
| 154 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.