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