| Conditions | 19 |
| Paths | 1728 |
| Total Lines | 177 |
| 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 |
||
| 56 | * @param int $newRev |
||
| 57 | * @return $this |
||
| 58 | */ |
||
| 59 | public function compare($oldRev, $newRev) |
||
| 60 | { |
||
| 61 | $this->oldRev = $oldRev; |
||
| 62 | $this->newRev = $newRev; |
||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Gets or Sets preference of the Ui\Diff object |
||
| 68 | * |
||
| 69 | * @param string|array $prefs a key name or key-value pair(s) |
||
| 70 | * @param mixed $value value used when the first args is string |
||
| 71 | * @return array|$this |
||
| 72 | */ |
||
| 73 | public function preference($prefs = null, $value = null) |
||
| 74 | { |
||
| 75 | // set |
||
| 76 | if (is_string($prefs) && isset($value)) { |
||
| 77 | $this->preference[$prefs] = $value; |
||
| 78 | return $this; |
||
| 79 | } elseif (is_array($prefs)) { |
||
| 80 | foreach ($prefs as $name => $value) { |
||
| 81 | $this->preference[$name] = $value; |
||
| 82 | } |
||
| 83 | return $this; |
||
| 84 | } |
||
| 85 | // get |
||
| 86 | return $this->preference; |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Retrieve requested revision(s) and difftype from Ui\Revisions |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | protected function preProcess() |
||
| 95 | { |
||
| 96 | global $INPUT; |
||
| 97 | |||
| 98 | // difflink icon click, eg. ?rev=123456789&do=diff |
||
| 99 | if ($INPUT->has('rev')) { |
||
| 100 | $this->oldRev = $INPUT->int('rev'); |
||
| 101 | $this->newRev = ''; // current revision |
||
| 102 | } |
||
| 103 | |||
| 104 | // submit button with two checked boxes |
||
| 105 | $rev2 = $INPUT->arr('rev2', []); |
||
| 106 | if (count($rev2) > 1) { |
||
| 107 | if ($rev2[0] == 'current') { |
||
| 108 | [$this->oldRev, $this->newRev] = [$rev2[1], '']; |
||
| 109 | } elseif ($rev2[1] == 'current') { |
||
| 110 | [$this->oldRev, $this->newRev] = [$rev2[0], '']; |
||
| 111 | } elseif ($rev2[0] < $rev2[1]) { |
||
| 112 | [$this->oldRev, $this->newRev] = [$rev2[0], $rev2[1]]; |
||
| 113 | } else { |
||
| 114 | [$this->oldRev, $this->newRev] = [$rev2[1], $rev2[0]]; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | // diff view type |
||
| 119 | if ($INPUT->has('difftype')) { |
||
| 120 | // retrieve requested $difftype |
||
| 121 | $this->preference['difftype'] = $INPUT->str('difftype'); |
||
| 122 | } else { |
||
| 123 | // read preference from DokuWiki cookie. PageDiff only |
||
| 124 | $mode = get_doku_pref('difftype', $mode = null); |
||
| 125 | if (isset($mode)) $this->preference['difftype'] = $mode; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * get extended revision info |
||
| 131 | * |
||
| 132 | * @param int|string $rev revision identifier, '' means current one |
||
| 133 | * @return array revision info structure of a page or media file |
||
| 134 | */ |
||
| 135 | protected function getExtendedRevisionInfo($rev) |
||
| 136 | { |
||
| 137 | $changelog =& $this->changelog; |
||
| 138 | |||
| 139 | if ($rev) { |
||
| 140 | $info = $changelog->getRevisionInfo($rev); |
||
| 141 | } elseif (file_exists($filename = $this->itemFN($this->id))) { |
||
| 142 | $rev = filemtime(fullpath($filename)); |
||
| 143 | $info = $changelog->getRevisionInfo($rev) + array( |
||
| 144 | 'current' => true, |
||
| 145 | ); |
||
| 146 | } else { // once exists, but now removed |
||
| 147 | $info = array( |
||
| 148 | 'current' => true, |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | return array('item' => $this->item) + $info; |
||
| 152 | } |
||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | /** |
||
| 157 | * Build header of diff HTML |
||
| 158 | * |
||
| 159 | * @param string $l_rev Left revisions |
||
| 160 | * @param string $r_rev Right revision |
||
| 161 | * @return string[] HTML snippets for diff header |
||
| 162 | * @deprecated 2020-12-31 |
||
| 163 | */ |
||
| 164 | public function buildDiffHead($l_rev, $r_rev) |
||
| 165 | { |
||
| 166 | dbg_deprecated('not used see '. \dokuwiki\Ui\PageDiff::class .'::show()'); |
||
| 167 | } |
||
| 168 | |||
| 169 | } |
||
| 170 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.