| Conditions | 11 |
| Paths | 56 |
| Total Lines | 69 |
| 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 |
||
| 81 | function render($mode, Doku_Renderer $renderer, $data) { |
||
| 82 | global $lang; |
||
| 83 | global $INFO; |
||
| 84 | global $ID; |
||
| 85 | |||
| 86 | $id = $ID; |
||
| 87 | // If it's a sidebar, get the original id. |
||
| 88 | if ($INFO != null) { |
||
| 89 | $id = $INFO['id']; |
||
| 90 | } |
||
| 91 | $match = $data[0]; |
||
| 92 | $match = ($match == '.') ? $id : $match; |
||
| 93 | if (strstr($match, ".:")) { |
||
| 94 | resolve_pageid(getNS($id), $match, $exists); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($mode == 'xhtml') { |
||
| 98 | $renderer->info['cache'] = false; |
||
| 99 | |||
| 100 | @require_once(DOKU_INC.'inc/fulltext.php'); |
||
| 101 | $backlinks = ft_backlinks($match); |
||
| 102 | |||
| 103 | dbglog($backlinks, "backlinks: all backlinks to: $match"); |
||
| 104 | |||
| 105 | $renderer->doc .= '<div id="plugin__backlinks">'.DW_LF; |
||
| 106 | |||
| 107 | $filterNS = $data[1]; |
||
| 108 | if (!empty($backlinks) && !empty($filterNS)) { |
||
| 109 | if (stripos($filterNS, "!", 0) === 0) { |
||
| 110 | $filterNS = substr($filterNS, 1); |
||
| 111 | dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS"); |
||
| 112 | $backlinks = array_filter($backlinks, function($ns) use($filterNS) { |
||
| 113 | return stripos($ns, $filterNS, 0) !== 0; |
||
| 114 | }); |
||
| 115 | } else { |
||
| 116 | dbglog($filterNS, "backlinks: including namespace: $filterNS only"); |
||
| 117 | $backlinks = array_filter($backlinks, function($ns) use($filterNS) { |
||
| 118 | return stripos($ns, $filterNS, 0) === 0; |
||
| 119 | }); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | dbglog($backlinks, "backlinks: all backlinks to be rendered"); |
||
| 124 | |||
| 125 | if (!empty($backlinks)) { |
||
| 126 | |||
| 127 | $renderer->doc .= '<ul class="idx">'; |
||
| 128 | |||
| 129 | foreach ($backlinks as $backlink) { |
||
| 130 | $name = p_get_metadata($backlink, 'title'); |
||
| 131 | if (empty($name)) { |
||
| 132 | $name = $backlink; |
||
| 133 | } |
||
| 134 | $renderer->doc .= '<li><div class="li">'; |
||
| 135 | $renderer->doc .= html_wikilink(':'.$backlink, $name); |
||
| 136 | $renderer->doc .= '</div></li>'.DW_LF; |
||
| 137 | } |
||
| 138 | |||
| 139 | $renderer->doc .= '</ul>'.DW_LF; |
||
| 140 | } else { |
||
| 141 | $renderer->doc .= "<strong>Plugin Backlinks: ".$lang['nothingfound']."</strong>".DW_LF; |
||
| 142 | } |
||
| 143 | |||
| 144 | $renderer->doc .= '</div>'.DW_LF; |
||
| 145 | |||
| 146 | return true; |
||
| 147 | } |
||
| 148 | return false; |
||
| 149 | } |
||
| 150 | } |
||
| 151 |
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.