| Conditions | 8 |
| Paths | 7 |
| Total Lines | 54 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 11 | ||
| Bugs | 2 | Features | 2 |
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 |
||
| 92 | function render($mode, Doku_Renderer $renderer, $data) { |
||
| 93 | global $lang; |
||
| 94 | |||
| 95 | if($mode == 'xhtml'){ |
||
| 96 | $renderer->info['cache'] = false; |
||
| 97 | |||
| 98 | @require_once(DOKU_INC.'inc/fulltext.php'); |
||
| 99 | $backlinks = ft_backlinks($data[0]); |
||
| 100 | |||
| 101 | dbglog($backlinks, "backlinks: all backlinks to: $data[0]"); |
||
| 102 | |||
| 103 | $renderer->doc .= '<div id="plugin__backlinks">' . DW_LF; |
||
| 104 | |||
| 105 | $filterNS = $data[1]; |
||
| 106 | if(!empty($backlinks) && !empty($filterNS)) { |
||
| 107 | if (stripos($filterNS, "!", 0) === 0) { |
||
| 108 | $filterNS = substr($filterNS, 1); |
||
| 109 | dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS"); |
||
| 110 | $backlinks= array_filter($backlinks, function($ns) use($filterNS) { |
||
| 111 | return stripos($ns, $filterNS, 0) !== 0; |
||
| 112 | }); |
||
| 113 | } else { |
||
| 114 | dbglog($filterNS, "backlinks: including namespace: $filterNS only"); |
||
| 115 | $backlinks= array_filter($backlinks, function($ns) use($filterNS) { |
||
| 116 | return stripos($ns, $filterNS, 0) === 0; |
||
| 117 | }); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | dbglog($backlinks, "backlinks: all backlinks to be rendered"); |
||
| 122 | |||
| 123 | if(!empty($backlinks)) { |
||
| 124 | |||
| 125 | $renderer->doc .= '<ul class="idx">'; |
||
| 126 | |||
| 127 | foreach($backlinks as $backlink){ |
||
| 128 | $name = p_get_metadata($backlink, 'title'); |
||
| 129 | if(empty($name)) $name = $backlink; |
||
| 130 | $renderer->doc .= '<li><div class="li">'; |
||
| 131 | $renderer->doc .= html_wikilink(':'.$backlink, $name); |
||
| 132 | $renderer->doc .= '</div></li>' . DW_LF; |
||
| 133 | } |
||
| 134 | |||
| 135 | $renderer->doc .= '</ul>' . DW_LF; |
||
| 136 | } else { |
||
| 137 | $renderer->doc .= "<strong>Plugin Backlinks: " . $lang['nothingfound'] . "</strong>" . DW_LF; |
||
| 138 | } |
||
| 139 | |||
| 140 | $renderer->doc .= '</div>' . DW_LF; |
||
| 141 | |||
| 142 | return true; |
||
| 143 | } |
||
| 144 | return false; |
||
| 145 | } |
||
| 146 | } |
||
| 147 |
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.