| Conditions | 6 |
| Paths | 14 |
| 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 |
||
| 55 | public function show($first = 0) |
||
| 56 | { |
||
| 57 | global $lang; |
||
| 58 | |||
| 59 | // get revisions, and set correct pagenation parameters (first, hasNext) |
||
| 60 | if ($first === null) $first = 0; |
||
| 61 | $hasNext = false; |
||
| 62 | $revisions = $this->getRevisions($first, $hasNext); |
||
| 63 | |||
| 64 | // create the form |
||
| 65 | $form = new Form([ |
||
| 66 | 'id' => 'page__revisions', // must not be "media__revisions" |
||
| 67 | 'action' => media_managerURL(['image' => $this->id], '&'), |
||
| 68 | 'class' => 'changes', |
||
| 69 | ]); |
||
| 70 | $form->setHiddenField('mediado', 'diff'); // required for media revisions |
||
| 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 (file_exists(mediaFN($this->id, $rev))) { |
||
| 84 | $form->addCheckbox('rev2[]')->val($rev); |
||
| 85 | } else { |
||
| 86 | $form->addCheckbox('')->val($rev)->attr('disabled','disabled'); |
||
| 87 | } |
||
| 88 | $form->addHTML(' '); |
||
| 89 | |||
| 90 | $objRevInfo = $this->getObjRevInfo($info); |
||
| 91 | $html = implode(' ', [ |
||
| 92 | $objRevInfo->editDate(), // edit date and time |
||
| 93 | $objRevInfo->difflink(), // link to diffview icon |
||
| 94 | $objRevInfo->itemName(), // name of page or media |
||
| 95 | '<div>', |
||
| 96 | $objRevInfo->editSummary(), // edit summary |
||
| 97 | $objRevInfo->editor(), // editor info |
||
| 98 | $objRevInfo->sizechange(), // size change indicator |
||
| 99 | $objRevInfo->currentIndicator(), // current indicator (only when k=1) |
||
| 100 | '</div>', |
||
| 101 | ]); |
||
| 102 | $form->addHTML($html); |
||
| 103 | |||
| 104 | $form->addTagClose('div'); |
||
| 105 | $form->addTagClose('li'); |
||
| 106 | } |
||
| 107 | $form->addTagClose('ul'); // end of revision list |
||
| 108 | |||
| 109 | // show button for diff view |
||
| 110 | $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit'); |
||
| 111 | |||
| 112 | $form->addTagClose('div'); // close div class=no |
||
| 113 | |||
| 114 | print $form->toHTML('Revisions'); |
||
| 115 | |||
| 116 | // provide navigation for pagenated revision list (of pages and/or media files) |
||
| 117 | print $this->navigation($first, $hasNext, function ($n) { |
||
| 118 | return media_managerURL(['first' => $n], '&', false, true); |
||
| 119 | }); |
||
| 120 | } |
||
| 121 | |||
| 123 |