| Conditions | 3 |
| Paths | 1 |
| Total Lines | 129 |
| 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 |
||
| 206 | protected function getObjRevInfo(array $info) |
||
| 207 | { |
||
| 208 | return new class ($info) // anonymous class (objRevInfo) |
||
| 209 | { |
||
| 210 | protected $info; |
||
| 211 | |||
| 212 | public function __construct(array $info) |
||
| 213 | { |
||
| 214 | $this->info = $info; |
||
| 215 | } |
||
| 216 | |||
| 217 | // fileicon of the page or media file |
||
| 218 | public function itemIcon() |
||
| 219 | { |
||
| 220 | $id = $this->info['id']; |
||
| 221 | if (isset($this->info['media'])) { |
||
| 222 | $html = media_printicon($id); |
||
| 223 | } else { |
||
| 224 | $html = '<img class="icon" src="'.DOKU_BASE.'lib/images/fileicons/file.png" alt="'.$id.'" />'; |
||
| 225 | } |
||
| 226 | return $html; |
||
| 227 | } |
||
| 228 | |||
| 229 | // edit date and time of the page or media file |
||
| 230 | public function editDate() |
||
| 231 | { |
||
| 232 | return '<span class="date">'. dformat($this->info['date']) .'</span>'; |
||
| 233 | } |
||
| 234 | |||
| 235 | // edit summary |
||
| 236 | public function editSummary() |
||
| 237 | { |
||
| 238 | return '<span class="sum">'.' – '. hsc($this->info['sum']).'</span>'; |
||
| 239 | } |
||
| 240 | |||
| 241 | // editor of the page or media file |
||
| 242 | public function editor() |
||
| 243 | { |
||
| 244 | $html = '<span class="user">'; |
||
| 245 | if ($this->info['user']) { |
||
| 246 | $html.= '<bdi>'. editorinfo($this->info['user']) .'</bdi>'; |
||
| 247 | if (auth_ismanager()) $html.= ' <bdo dir="ltr">('. $this->info['ip'] .')</bdo>'; |
||
| 248 | } else { |
||
| 249 | $html.= '<bdo dir="ltr">'. $this->info['ip'] .'</bdo>'; |
||
| 250 | } |
||
| 251 | $html.= '</span>'; |
||
| 252 | return $html; |
||
| 253 | } |
||
| 254 | |||
| 255 | // name of the page or media file |
||
| 256 | public function itemName() |
||
| 257 | { |
||
| 258 | $id = $this->info['id']; |
||
| 259 | if (isset($this->info['media'])) { |
||
| 260 | $href = media_managerURL(['tab_details'=>'view', 'image'=> $id, 'ns'=> getNS($id)], '&'); |
||
| 261 | $class = file_exists(mediaFN($id)) ? 'wikilink1' : 'wikilink2'; |
||
| 262 | $html = '<a href="'.$href.'" class="'.$class.'">'.$id.'</a>'; |
||
| 263 | } else { |
||
| 264 | $html = html_wikilink(':'.$id, (useHeading('navigation') ? null : $id)); |
||
| 265 | } |
||
| 266 | return $html; |
||
| 267 | } |
||
| 268 | |||
| 269 | // icon difflink |
||
| 270 | public function difflink() |
||
| 271 | { |
||
| 272 | global $lang; |
||
| 273 | $id = $this->info['id']; |
||
| 274 | |||
| 275 | if (isset($this->info['media'])) { |
||
| 276 | $revs = (new MediaChangeLog($id))->getRevisions(0, 1); |
||
| 277 | $diff = (count($revs) && file_exists(mediaFN($id))); |
||
| 278 | if ($diff) { |
||
| 279 | $href = media_managerURL( |
||
| 280 | ['tab_details'=>'history', 'mediado'=>'diff', 'image'=> $id, 'ns'=> getNS($id)], '&' |
||
| 281 | ); |
||
| 282 | } else { |
||
| 283 | $href = ''; |
||
| 284 | } |
||
| 285 | } else { |
||
| 286 | $href = wl($id, "do=diff", false, '&'); |
||
| 287 | } |
||
| 288 | |||
| 289 | if ($href) { |
||
| 290 | $html = '<a href="'.$href.'" class="diff_link">' |
||
| 291 | . '<img src="'.DOKU_BASE.'lib/images/diff.png" width="15" height="11"' |
||
| 292 | . ' title="'.$lang['diff'].'" alt="'.$lang['diff'].'" />' |
||
| 293 | . '</a>'; |
||
| 294 | } else { |
||
| 295 | $html = '<img src="'.DOKU_BASE.'lib/images/blank.gif" width="15" height="11" alt="" />'; |
||
| 296 | } |
||
| 297 | return $html; |
||
| 298 | } |
||
| 299 | |||
| 300 | // icon revision link |
||
| 301 | public function revisionlink() |
||
| 302 | { |
||
| 303 | global $lang; |
||
| 304 | $id = $this->info['id']; |
||
| 305 | if (isset($this->info['media'])) { |
||
| 306 | $href = media_managerURL(['tab_details'=>'history', 'image'=> $id, 'ns'=> getNS($id)], '&'); |
||
| 307 | } else { |
||
| 308 | $href = wl($id, "do=revisions", false, '&'); |
||
| 309 | } |
||
| 310 | $html = '<a href="'.$href.'" class="revisions_link">' |
||
| 311 | . '<img src="'.DOKU_BASE.'lib/images/history.png" width="12" height="14"' |
||
| 312 | . ' title="'.$lang['btn_revs'].'" alt="'.$lang['btn_revs'].'" />' |
||
| 313 | . '</a>'; |
||
| 314 | return $html; |
||
| 315 | } |
||
| 316 | |||
| 317 | // size change |
||
| 318 | public function sizeChange() |
||
| 319 | { |
||
| 320 | $class = 'sizechange'; |
||
| 321 | $value = filesize_h(abs($this->info['sizechange'])); |
||
| 322 | if ($this->info['sizechange'] > 0) { |
||
| 323 | $class .= ' positive'; |
||
| 324 | $value = '+' . $value; |
||
| 325 | } elseif ($this->info['sizechange'] < 0) { |
||
| 326 | $class .= ' negative'; |
||
| 327 | $value = '-' . $value; |
||
| 328 | } else { |
||
| 329 | $value = '±' . $value; |
||
| 330 | } |
||
| 331 | return '<span class="'.$class.'">'.$value.'</span>'; |
||
| 332 | } |
||
| 333 | }; // end of anonymous class (objRevInfo) |
||
| 334 | } |
||
| 335 | |||
| 337 |