| Conditions | 11 |
| Paths | 56 |
| Total Lines | 72 |
| 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( |
||
| 110 | $backlinks, function ($ns) use ($filterNS) { |
||
| 111 | return stripos($ns, $filterNS, 0) !== 0; |
||
| 112 | } |
||
| 113 | ); |
||
| 114 | } else { |
||
| 115 | dbglog($filterNS, "backlinks: including namespace: $filterNS only"); |
||
| 116 | $backlinks = array_filter( |
||
| 117 | $backlinks, function ($ns) use ($filterNS) { |
||
| 118 | return stripos($ns, $filterNS, 0) === 0; |
||
| 119 | } |
||
| 120 | ); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | dbglog($backlinks, "backlinks: all backlinks to be rendered"); |
||
| 125 | |||
| 126 | if(!empty($backlinks)) { |
||
| 127 | |||
| 128 | $renderer->doc .= '<ul class="idx">'; |
||
| 129 | |||
| 130 | foreach($backlinks as $backlink) { |
||
| 131 | $name = p_get_metadata($backlink, 'title'); |
||
| 132 | if(empty($name)) { |
||
| 133 | $name = $backlink; |
||
| 134 | } |
||
| 135 | $renderer->doc .= '<li><div class="li">'; |
||
| 136 | $renderer->doc .= html_wikilink(':' . $backlink, $name); |
||
| 137 | $renderer->doc .= '</div></li>' . "\n"; |
||
| 138 | } |
||
| 139 | |||
| 140 | $renderer->doc .= '</ul>' . "\n"; |
||
| 141 | } else { |
||
| 142 | $renderer->doc .= "<strong>Plugin Backlinks: " . $lang['nothingfound'] . "</strong>" . "\n"; |
||
| 143 | } |
||
| 144 | |||
| 145 | $renderer->doc .= '</div>' . "\n"; |
||
| 146 | |||
| 147 | return true; |
||
| 148 | } |
||
| 149 | return false; |
||
| 150 | } |
||
| 151 | } |
||
| 152 |
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.