| 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 |
||
| 140 | public function getObjRevInfo(array $info) |
||
| 141 | { |
||
| 142 | return new class ($info) // anonymous class (objRevInfo) |
||
| 143 | { |
||
| 144 | protected $info; |
||
| 145 | |||
| 146 | public function __construct(array $info) |
||
| 147 | { |
||
| 148 | if (!isset($info['current'])) { |
||
| 149 | $info['current'] = false; |
||
| 150 | } |
||
| 151 | $this->info = $info; |
||
| 152 | } |
||
| 153 | |||
| 154 | // current indicator |
||
| 155 | public function currentIndicator() |
||
| 156 | { |
||
| 157 | global $lang; |
||
| 158 | return ($this->info['current']) ? '('.$lang['current'].')' : ''; |
||
| 159 | } |
||
| 160 | |||
| 161 | // edit date and time of the page or media file |
||
| 162 | public function editDate() |
||
| 163 | { |
||
| 164 | return '<span class="date">'. dformat($this->info['date']) .'</span>'; |
||
| 165 | } |
||
| 166 | |||
| 167 | // edit summary |
||
| 168 | public function editSummary() |
||
| 169 | { |
||
| 170 | return '<span class="sum">'.' – '. hsc($this->info['sum']).'</span>'; |
||
| 171 | } |
||
| 172 | |||
| 173 | // editor of the page or media file |
||
| 174 | public function editor() |
||
| 175 | { |
||
| 176 | // slightly different with display of Ui\Recent, i.e. external edit |
||
| 177 | global $lang; |
||
| 178 | $html = '<span class="user">'; |
||
| 179 | if (!$this->info['user'] && !$this->info['ip']) { |
||
| 180 | $html.= '('.$lang['external_edit'].')'; |
||
| 181 | } elseif ($this->info['user']) { |
||
| 182 | $html.= '<bdi>'. editorinfo($this->info['user']) .'</bdi>'; |
||
| 183 | if (auth_ismanager()) $html.= ' <bdo dir="ltr">('. $this->info['ip'] .')</bdo>'; |
||
| 184 | } else { |
||
| 185 | $html.= '<bdo dir="ltr">'. $this->info['ip'] .'</bdo>'; |
||
| 186 | } |
||
| 187 | $html.= '</span>'; |
||
| 188 | return $html; |
||
| 189 | } |
||
| 190 | |||
| 191 | // name of the page or media file |
||
| 192 | public function itemName() |
||
| 193 | { |
||
| 194 | // slightly different with display of Ui\Recent, i.e. revison may not exists |
||
| 195 | $id = $this->info['id']; |
||
| 196 | $rev = $this->info['date']; |
||
| 197 | |||
| 198 | switch ($this->info['item']) { |
||
| 199 | case 'media': // media file revision |
||
| 200 | if (isset($this->info['current'])) { |
||
| 201 | $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view'], '&'); |
||
| 202 | $html = '<a href="'.$href.'" class="wikilink1">'.$id.'</a>'; |
||
| 203 | } elseif (file_exists(mediaFN($id, $rev))) { |
||
| 204 | $href = media_managerURL(['image'=> $id, 'tab_details'=> 'view', 'rev'=> $rev], '&'); |
||
| 205 | $html = '<a href="'.$href.'" class="wikilink1">'.$id.'</a>'; |
||
| 206 | } else { |
||
| 207 | $html = $id; |
||
| 208 | } |
||
| 209 | return $html; |
||
| 210 | case 'page': // page revision |
||
| 211 | $display_name = useHeading('navigation') ? hsc(p_get_first_heading($id)) : $id; |
||
| 212 | if (!$display_name) $display_name = $id; |
||
| 213 | if ($this->info['current'] || page_exists($id, $rev)) { |
||
| 214 | $href = wl($id, "rev=$rev", false, '&'); |
||
| 215 | $html = '<a href="'.$href.'" class="wikilink1">'.$display_name.'</a>'; |
||
| 216 | } else { |
||
| 217 | $html = $display_name; |
||
| 218 | } |
||
| 219 | return $html; |
||
| 220 | } |
||
| 221 | return ''; |
||
| 222 | } |
||
| 223 | |||
| 224 | // icon difflink |
||
| 225 | public function difflink() |
||
| 226 | { |
||
| 227 | global $lang; |
||
| 228 | $id = $this->info['id']; |
||
| 229 | $rev = $this->info['date']; |
||
| 230 | |||
| 231 | switch ($this->info['item']) { |
||
| 232 | case 'media': // media file revision |
||
| 233 | if (isset($this->info['current']) || !file_exists(mediaFN($id, $rev))) { |
||
| 234 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 235 | } else { |
||
| 236 | $href = media_managerURL(['image'=> $id, 'rev'=> $rev, 'mediado'=>'diff'], '&'); |
||
| 237 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 238 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 239 | . ' title="'. $lang['diff'] .'" alt="'.$lang['diff'] .'" />' |
||
| 240 | . '</a> '; |
||
| 241 | } |
||
| 242 | return $html; |
||
| 243 | case 'page': // page revision |
||
| 244 | if ($this->info['current'] || !page_exists($id, $rev)) { |
||
| 245 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 246 | } else { |
||
| 247 | $href = wl($id, "rev=$rev,do=diff", false, '&'); |
||
| 248 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 249 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 250 | . ' title="'.$lang['diff'].'" alt="'.$lang['diff'].'" />' |
||
| 251 | . '</a>'; |
||
| 252 | } |
||
| 253 | return $html; |
||
| 254 | } |
||
| 255 | return ''; |
||
| 256 | } |
||
| 257 | |||
| 258 | // size change |
||
| 259 | public function sizeChange() |
||
| 260 | { |
||
| 261 | $class = 'sizechange'; |
||
| 262 | $value = filesize_h(abs($this->info['sizechange'])); |
||
| 263 | if ($this->info['sizechange'] > 0) { |
||
| 264 | $class .= ' positive'; |
||
| 265 | $value = '+' . $value; |
||
| 266 | } elseif ($this->info['sizechange'] < 0) { |
||
| 267 | $class .= ' negative'; |
||
| 268 | $value = '-' . $value; |
||
| 269 | } else { |
||
| 270 | $value = '±' . $value; |
||
| 271 | } |
||
| 272 | return '<span class="'.$class.'">'.$value.'</span>'; |
||
| 273 | } |
||
| 274 | }; // end of anonymous class (objRevInfo) |
||
| 275 | } |
||
| 276 | |||
| 278 |