| Conditions | 3 |
| Paths | 1 |
| Total Lines | 136 |
| 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 |
||
| 322 | protected function getObjRevInfo(array $info) |
||
| 323 | { |
||
| 324 | return new class ($info) // anonymous class (objRevInfo) |
||
| 325 | { |
||
| 326 | protected $info; |
||
| 327 | |||
| 328 | public function __construct(array $info) |
||
| 329 | { |
||
| 330 | if (!isset($info['current'])) { |
||
| 331 | $info['current'] = false; |
||
| 332 | } |
||
| 333 | $this->info = $info; |
||
| 334 | } |
||
| 335 | |||
| 336 | // current indicator |
||
| 337 | public function currentIndicator() |
||
| 338 | { |
||
| 339 | global $lang; |
||
| 340 | return ($this->info['current']) ? '('.$lang['current'].')' : ''; |
||
| 341 | } |
||
| 342 | |||
| 343 | // edit date and time of the page or media file |
||
| 344 | public function editDate() |
||
| 345 | { |
||
| 346 | return '<span class="date">'. dformat($this->info['date']) .'</span>'; |
||
| 347 | } |
||
| 348 | |||
| 349 | // edit summary |
||
| 350 | public function editSummary() |
||
| 351 | { |
||
| 352 | return '<span class="sum">'.' – '. hsc($this->info['sum']).'</span>'; |
||
| 353 | } |
||
| 354 | |||
| 355 | // editor of the page or media file |
||
| 356 | public function editor() |
||
| 357 | { |
||
| 358 | // slightly different with display of Ui\Recent, i.e. external edit |
||
| 359 | global $lang; |
||
| 360 | $html = '<span class="user">'; |
||
| 361 | if (!$this->info['user'] && !$this->info['ip']) { |
||
| 362 | $html.= '('.$lang['external_edit'].')'; |
||
| 363 | } elseif ($this->info['user']) { |
||
| 364 | $html.= '<bdi>'. editorinfo($this->info['user']) .'</bdi>'; |
||
| 365 | if (auth_ismanager()) $html.= ' <bdo dir="ltr">('. $this->info['ip'] .')</bdo>'; |
||
| 366 | } else { |
||
| 367 | $html.= '<bdo dir="ltr">'. $this->info['ip'] .'</bdo>'; |
||
| 368 | } |
||
| 369 | $html.= '</span>'; |
||
| 370 | return $html; |
||
| 371 | } |
||
| 372 | |||
| 373 | // name of the page or media file |
||
| 374 | public function itemName() |
||
| 375 | { |
||
| 376 | // slightly different with display of Ui\Recent, i.e. revison may not exists |
||
| 377 | $id = $this->info['id']; |
||
| 378 | $rev = $this->info['date']; |
||
| 379 | |||
| 380 | if (isset($this->info['media'])) { |
||
| 381 | // media file revision |
||
| 382 | if (isset($this->info['current'])) { |
||
| 383 | $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view'], '&'); |
||
| 384 | $html = '<a href="'.$href.'" class="wikilink1">'.$id.'</a>'; |
||
| 385 | } elseif (file_exists(mediaFN($id, $rev))) { |
||
| 386 | $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view', 'rev'=> $rev], '&'); |
||
| 387 | $html = '<a href="'.$href.'" class="wikilink1">'.$id.'</a>'; |
||
| 388 | } else { |
||
| 389 | $html = $id; |
||
| 390 | } |
||
| 391 | return $html; |
||
| 392 | } else { |
||
| 393 | // page revision |
||
| 394 | $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; |
||
| 395 | if (!$display_name) $display_name = $id; |
||
| 396 | if ($this->info['current'] || page_exists($id, $rev)) { |
||
| 397 | $href = wl($id, "rev=$rev", false, '&'); |
||
| 398 | $html = '<a href="'.$href.'" class="wikilink1">'.$display_name.'</a>'; |
||
| 399 | } else { |
||
| 400 | $html = $display_name; |
||
| 401 | } |
||
| 402 | return $html; |
||
| 403 | } |
||
| 404 | } |
||
| 405 | |||
| 406 | // icon difflink |
||
| 407 | public function difflink() |
||
| 408 | { |
||
| 409 | global $lang; |
||
| 410 | $id = $this->info['id']; |
||
| 411 | $rev = $this->info['date']; |
||
| 412 | |||
| 413 | if (isset($this->info['media'])) { |
||
| 414 | // media file revision |
||
| 415 | if (isset($this->info['current']) || !file_exists(mediaFN($id, $rev))) { |
||
| 416 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 417 | } else { |
||
| 418 | $href = media_managerURL(['image'=> $id, 'rev'=> $rev, 'mediado'=>'diff'], '&'); |
||
| 419 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 420 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 421 | . ' title="'. $lang['diff'] .'" alt="'.$lang['diff'] .'" />' |
||
| 422 | . '</a> '; |
||
| 423 | } |
||
| 424 | return $html; |
||
| 425 | } else { |
||
| 426 | // page revision |
||
| 427 | if ($this->info['current'] || !page_exists($id, $rev)) { |
||
| 428 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 429 | } else { |
||
| 430 | $href = wl($id, "rev=$rev,do=diff", false, '&'); |
||
| 431 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 432 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 433 | . ' title="'.$lang['diff'].'" alt="'.$lang['diff'].'" />' |
||
| 434 | . '</a>'; |
||
| 435 | } |
||
| 436 | return $html; |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | // size change |
||
| 441 | public function sizeChange() |
||
| 442 | { |
||
| 443 | $class = 'sizechange'; |
||
| 444 | $value = filesize_h(abs($this->info['sizechange'])); |
||
| 445 | if ($this->info['sizechange'] > 0) { |
||
| 446 | $class .= ' positive'; |
||
| 447 | $value = '+' . $value; |
||
| 448 | } elseif ($this->info['sizechange'] < 0) { |
||
| 449 | $class .= ' negative'; |
||
| 450 | $value = '-' . $value; |
||
| 451 | } else { |
||
| 452 | $value = '±' . $value; |
||
| 453 | } |
||
| 454 | return '<span class="'.$class.'">'.$value.'</span>'; |
||
| 455 | } |
||
| 456 | }; // end of anonymous class (objRevInfo) |
||
| 457 | } |
||
| 458 | |||
| 460 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.