Conditions | 8 |
Paths | 7 |
Total Lines | 55 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
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 |
||
91 | function render($mode, Doku_Renderer $renderer, $data) { |
||
92 | global $lang; |
||
93 | |||
94 | if($mode == 'xhtml'){ |
||
95 | $renderer->info['cache'] = false; |
||
96 | |||
97 | @require_once(DOKU_INC.'inc/fulltext.php'); |
||
98 | $backlinks = ft_backlinks($data[0]); |
||
99 | |||
100 | dbglog($backlinks, "backlinks: all backlinks to: $data[0]"); |
||
101 | |||
102 | $renderer->doc .= '<div id="plugin__backlinks">' . DW_LF; |
||
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)) $name = $backlink; |
||
129 | $renderer->doc .= '<li><div class="li">'; |
||
130 | //$renderer->doc .= html_wikilink(':'.$backlink, $name); |
||
131 | $renderer->doc .= '<a href="'.wl(':'.$backlink).'">'.$name.'</a>'; |
||
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.