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