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