| Conditions | 3 |
| Paths | 1 |
| Total Lines | 129 |
| 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 |
||
| 204 | protected function getObjRevInfo(array $info) |
||
| 205 | { |
||
| 206 | return new class ($info) // anonymous class (objRevInfo) |
||
| 207 | { |
||
| 208 | protected $info; |
||
| 209 | |||
| 210 | public function __construct(array $info) |
||
| 211 | { |
||
| 212 | $this->info = $info; |
||
| 213 | } |
||
| 214 | |||
| 215 | // fileicon of the page or media file |
||
| 216 | public function itemIcon() |
||
| 217 | { |
||
| 218 | $id = $this->info['id']; |
||
| 219 | if (isset($this->info['media'])) { |
||
| 220 | $html = media_printicon($id); |
||
| 221 | } else { |
||
| 222 | $html = '<img class="icon" src="'.DOKU_BASE.'lib/images/fileicons/file.png" alt="'.$id.'" />'; |
||
| 223 | } |
||
| 224 | return $html; |
||
| 225 | } |
||
| 226 | |||
| 227 | // edit date and time of the page or media file |
||
| 228 | public function editDate() |
||
| 229 | { |
||
| 230 | return '<span class="date">'. dformat($this->info['date']) .'</span>'; |
||
| 231 | } |
||
| 232 | |||
| 233 | // edit summary |
||
| 234 | public function editSummary() |
||
| 235 | { |
||
| 236 | return '<span class="sum">'.' – '. hsc($this->info['sum']).'</span>'; |
||
| 237 | } |
||
| 238 | |||
| 239 | // editor of the page or media file |
||
| 240 | public function editor() |
||
| 241 | { |
||
| 242 | $html = '<span class="user">'; |
||
| 243 | if ($this->info['user']) { |
||
| 244 | $html.= '<bdi>'. editorinfo($this->info['user']) .'</bdi>'; |
||
| 245 | if (auth_ismanager()) $html.= ' <bdo dir="ltr">('. $this->info['ip'] .')</bdo>'; |
||
| 246 | } else { |
||
| 247 | $html.= '<bdo dir="ltr">'. $this->info['ip'] .'</bdo>'; |
||
| 248 | } |
||
| 249 | $html.= '</span>'; |
||
| 250 | return $html; |
||
| 251 | } |
||
| 252 | |||
| 253 | // name of the page or media file |
||
| 254 | public function itemName() |
||
| 255 | { |
||
| 256 | $id = $this->info['id']; |
||
| 257 | if (isset($this->info['media'])) { |
||
| 258 | $href = media_managerURL(['tab_details'=>'view', 'image'=> $id, 'ns'=> getNS($id)], '&'); |
||
| 259 | $class = file_exists(mediaFN($id)) ? 'wikilink1' : 'wikilink2'; |
||
| 260 | $html = '<a href="'.$href.'" class="'.$class.'">'.$id.'</a>'; |
||
| 261 | } else { |
||
| 262 | $html = html_wikilink(':'.$id, (useHeading('navigation') ? null : $id)); |
||
| 263 | } |
||
| 264 | return $html; |
||
| 265 | } |
||
| 266 | |||
| 267 | // icon difflink |
||
| 268 | public function difflink() |
||
| 269 | { |
||
| 270 | global $lang; |
||
| 271 | $id = $this->info['id']; |
||
| 272 | |||
| 273 | if (isset($this->info['media'])) { |
||
| 274 | $revs = (new MediaChangeLog($id))->getRevisions(0, 1); |
||
| 275 | $diff = (count($revs) && file_exists(mediaFN($id))); |
||
| 276 | if ($diff) { |
||
| 277 | $href = media_managerURL( |
||
| 278 | ['tab_details'=>'history', 'mediado'=>'diff', 'image'=> $id, 'ns'=> getNS($id)], '&' |
||
| 279 | ); |
||
| 280 | } else { |
||
| 281 | $href = ''; |
||
| 282 | } |
||
| 283 | } else { |
||
| 284 | $href = wl($id, "do=diff", false, '&'); |
||
| 285 | } |
||
| 286 | |||
| 287 | if ($href) { |
||
| 288 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 289 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 290 | . ' title="'.$lang['diff'].'" alt="'.$lang['diff'].'" />' |
||
| 291 | . '</a>'; |
||
| 292 | } else { |
||
| 293 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 294 | } |
||
| 295 | return $html; |
||
| 296 | } |
||
| 297 | |||
| 298 | // icon revision link |
||
| 299 | public function revisionlink() |
||
| 300 | { |
||
| 301 | global $lang; |
||
| 302 | $id = $this->info['id']; |
||
| 303 | if (isset($this->info['media'])) { |
||
| 304 | $href = media_managerURL(['tab_details'=>'history', 'image'=> $id, 'ns'=> getNS($id)], '&'); |
||
| 305 | } else { |
||
| 306 | $href = wl($id, "do=revisions", false, '&'); |
||
| 307 | } |
||
| 308 | $html = '<a href="'.$href.'" class="revisions_link">' |
||
| 309 | . '<img src="'.DOKU_BASE.'lib/images/history.png" width="12" height="14"' |
||
| 310 | . ' title="'.$lang['btn_revs'].'" alt="'.$lang['btn_revs'].'" />' |
||
| 311 | . '</a>'; |
||
| 312 | return $html; |
||
| 313 | } |
||
| 314 | |||
| 315 | // size change |
||
| 316 | public function sizeChange() |
||
| 317 | { |
||
| 318 | $class = 'sizechange'; |
||
| 319 | $value = filesize_h(abs($this->info['sizechange'])); |
||
| 320 | if ($this->info['sizechange'] > 0) { |
||
| 321 | $class .= ' positive'; |
||
| 322 | $value = '+' . $value; |
||
| 323 | } elseif ($this->info['sizechange'] < 0) { |
||
| 324 | $class .= ' negative'; |
||
| 325 | $value = '-' . $value; |
||
| 326 | } else { |
||
| 327 | $value = '±' . $value; |
||
| 328 | } |
||
| 329 | return '<span class="'.$class.'">'.$value.'</span>'; |
||
| 330 | } |
||
| 331 | }; // end of anonymous class (objRevInfo) |
||
| 332 | } |
||
| 333 | |||
| 335 |