| Conditions | 7 |
| Paths | 18 |
| Total Lines | 66 |
| 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 |
||
| 54 | public function show($first = 0) |
||
| 55 | { |
||
| 56 | global $lang, $REV; |
||
| 57 | |||
| 58 | // get revisions, and set correct pagenation parameters (first, hasNext) |
||
| 59 | if ($first === null) $first = 0; |
||
| 60 | $hasNext = false; |
||
| 61 | $revisions = $this->getRevisions($first, $hasNext); |
||
| 62 | |||
| 63 | // print intro |
||
| 64 | print p_locale_xhtml('revisions'); |
||
| 65 | |||
| 66 | // create the form |
||
| 67 | $form = new Form([ |
||
| 68 | 'id' => 'page__revisions', |
||
| 69 | 'class' => 'changes', |
||
| 70 | ]); |
||
| 71 | $form->addTagOpen('div')->addClass('no'); |
||
| 72 | |||
| 73 | // start listing |
||
| 74 | $form->addTagOpen('ul'); |
||
| 75 | foreach ($revisions as $info) { |
||
| 76 | $rev = $info['date']; |
||
| 77 | $class = ($info['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : ''; |
||
| 78 | $form->addTagOpen('li')->addClass($class); |
||
| 79 | $form->addTagOpen('div')->addClass('li'); |
||
| 80 | |||
| 81 | if (isset($info['current'])) { |
||
| 82 | $form->addCheckbox('rev2[]')->val('current'); |
||
| 83 | } elseif ($rev == $REV) { |
||
| 84 | $form->addCheckbox('rev2[]')->val($rev)->attr('checked','checked'); |
||
| 85 | } elseif (page_exists($this->id, $rev)) { |
||
| 86 | $form->addCheckbox('rev2[]')->val($rev); |
||
| 87 | } else { |
||
| 88 | $form->addCheckbox('')->val($rev)->attr('disabled','disabled'); |
||
| 89 | } |
||
| 90 | $form->addHTML(' '); |
||
| 91 | |||
| 92 | $objRevInfo = $this->getObjRevInfo($info); |
||
| 93 | $html = implode(' ', [ |
||
| 94 | $objRevInfo->editDate(), // edit date and time |
||
| 95 | $objRevInfo->difflink(), // link to diffview icon |
||
| 96 | $objRevInfo->itemName(), // name of page or media |
||
| 97 | $objRevInfo->editSummary(), // edit summary |
||
| 98 | $objRevInfo->editor(), // editor info |
||
| 99 | $objRevInfo->sizechange(), // size change indicator |
||
| 100 | $objRevInfo->currentIndicator(), // current indicator (only when k=1) |
||
| 101 | ]); |
||
| 102 | $form->addHTML($html); |
||
| 103 | $form->addTagClose('div'); |
||
| 104 | $form->addTagClose('li'); |
||
| 105 | } |
||
| 106 | $form->addTagClose('ul'); // end of revision list |
||
| 107 | |||
| 108 | // show button for diff view |
||
| 109 | $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit'); |
||
| 110 | |||
| 111 | $form->addTagClose('div'); // close div class=no |
||
| 112 | |||
| 113 | print $form->toHTML('Revisions'); |
||
| 114 | |||
| 115 | // provide navigation for pagenated revision list (of pages and/or media files) |
||
| 116 | print $this->navigation($first, $hasNext, function ($n) { |
||
| 117 | return array('do' => 'revisions', 'first' => $n); |
||
| 118 | }); |
||
| 119 | } |
||
| 120 | |||
| 182 |