| Conditions | 11 |
| Paths | 56 |
| Total Lines | 68 |
| 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 |
||
| 79 | public function render($mode, Doku_Renderer $renderer, $data) { |
||
| 80 | global $lang; |
||
| 81 | global $INFO; |
||
| 82 | global $ID; |
||
| 83 | |||
| 84 | $id = $ID; |
||
| 85 | // If it's a sidebar, get the original id. |
||
| 86 | if ($INFO != null) { |
||
| 87 | $id = $INFO['id']; |
||
| 88 | } |
||
| 89 | $match = $data[0]; |
||
| 90 | $match = ($match == '.') ? $id : $match; |
||
| 91 | if (strstr($match, ".:")) { |
||
| 92 | resolve_pageid(getNS($id), $match, $exists); |
||
|
|
|||
| 93 | } |
||
| 94 | |||
| 95 | if ($mode == 'xhtml') { |
||
| 96 | $renderer->info['cache'] = false; |
||
| 97 | |||
| 98 | $backlinks = ft_backlinks($match); |
||
| 99 | |||
| 100 | dbglog($backlinks, "backlinks: all backlinks to: $match"); |
||
| 101 | |||
| 102 | $renderer->doc .= '<div id="plugin__backlinks">'."\n"; |
||
| 103 | |||
| 104 | $filterNS = $data[1]; |
||
| 105 | if (!empty($backlinks) && !empty($filterNS)) { |
||
| 106 | if (stripos($filterNS, "!", 0) === 0) { |
||
| 107 | $filterNS = substr($filterNS, 1); |
||
| 108 | dbglog($filterNS, "backlinks: exluding all of namespace: $filterNS"); |
||
| 109 | $backlinks = array_filter($backlinks, function ($ns) use ($filterNS) { |
||
| 110 | return stripos($ns, $filterNS, 0) !== 0; |
||
| 111 | }); |
||
| 112 | } else { |
||
| 113 | dbglog($filterNS, "backlinks: including namespace: $filterNS only"); |
||
| 114 | $backlinks = array_filter($backlinks, function ($ns) use ($filterNS) { |
||
| 115 | return stripos($ns, $filterNS, 0) === 0; |
||
| 116 | }); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | dbglog($backlinks, "backlinks: all backlinks to be rendered"); |
||
| 121 | |||
| 122 | if (!empty($backlinks)) { |
||
| 123 | |||
| 124 | $renderer->doc .= '<ul class="idx">'; |
||
| 125 | |||
| 126 | foreach ($backlinks as $backlink) { |
||
| 127 | $name = p_get_metadata($backlink, 'title'); |
||
| 128 | if (empty($name)) { |
||
| 129 | $name = $backlink; |
||
| 130 | } |
||
| 131 | $renderer->doc .= '<li><div class="li">'; |
||
| 132 | $renderer->doc .= html_wikilink(':'.$backlink, $name); |
||
| 133 | $renderer->doc .= '</div></li>'."\n"; |
||
| 134 | } |
||
| 135 | |||
| 136 | $renderer->doc .= '</ul>'."\n"; |
||
| 137 | } else { |
||
| 138 | $renderer->doc .= "<strong>Plugin Backlinks: ".$lang['nothingfound']."</strong>"."\n"; |
||
| 139 | } |
||
| 140 | |||
| 141 | $renderer->doc .= '</div>'."\n"; |
||
| 142 | |||
| 143 | return true; |
||
| 144 | } |
||
| 145 | return false; |
||
| 146 | } |
||
| 147 | } |
||
| 148 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.