Complex classes like BasePresenter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BasePresenter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | abstract class BasePresenter extends Nette\Application\UI\Presenter |
||
| 16 | { |
||
| 17 | |||
| 18 | const FLASH_TYPE_OK = 'success'; |
||
| 19 | const FLASH_TYPE_ERROR = 'alert'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | public $backlink = ''; |
||
| 25 | |||
| 26 | /** @var Model */ |
||
| 27 | protected $model; |
||
| 28 | |||
| 29 | /** @var Nette\DI\Container */ |
||
| 30 | protected $container; |
||
| 31 | |||
| 32 | /** @var Latte */ |
||
| 33 | protected $latte; |
||
| 34 | |||
| 35 | /** @var Router */ |
||
| 36 | protected $router; |
||
| 37 | |||
| 38 | /** @var string */ |
||
| 39 | protected $action; |
||
| 40 | |||
| 41 | /** @var Nette\Http\Request */ |
||
| 42 | protected $request; |
||
| 43 | |||
| 44 | /** @var integer */ |
||
| 45 | protected $meetingId; |
||
| 46 | |||
| 47 | protected $days = [ |
||
| 48 | 'pátek' => 'pátek', |
||
| 49 | 'sobota' => 'sobota', |
||
| 50 | 'neděle' => 'neděle', |
||
| 51 | ]; |
||
| 52 | |||
| 53 | protected $hours = [ |
||
| 54 | 0 => "00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23" |
||
|
|
|||
| 55 | ]; |
||
| 56 | |||
| 57 | protected $minutes = [ |
||
| 58 | 00 => "00", |
||
| 59 | 05 => "05", |
||
| 60 | 10 => "10", |
||
| 61 | 15 => "15", |
||
| 62 | 20 => "20", |
||
| 63 | 25 => "25", |
||
| 64 | 30 => "30", |
||
| 65 | 35 => "35", |
||
| 66 | 40 => "40", |
||
| 67 | 45 => "45", |
||
| 68 | 50 => "50", |
||
| 69 | 55 => "55", |
||
| 70 | ]; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Startup |
||
| 74 | */ |
||
| 75 | protected function startup() |
||
| 102 | |||
| 103 | |||
| 104 | /** |
||
| 105 | * Before render |
||
| 106 | * Prepare variables for template |
||
| 107 | */ |
||
| 108 | public function beforeRender() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * template |
||
| 148 | * @var string |
||
| 149 | */ |
||
| 150 | protected $template = 'listing'; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * template directory |
||
| 154 | * @var string |
||
| 155 | */ |
||
| 156 | protected $templateDir = ''; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * category ID |
||
| 160 | * @var integer |
||
| 161 | */ |
||
| 162 | protected $itemId = NULL; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * action what to do |
||
| 166 | * @var string |
||
| 167 | */ |
||
| 168 | protected $cms = ''; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * page where to return |
||
| 172 | * @var string |
||
| 173 | */ |
||
| 174 | protected $page = ''; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * heading tetxt |
||
| 178 | * @var string |
||
| 179 | */ |
||
| 180 | protected $heading = ''; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * action what to do next |
||
| 184 | * @var string |
||
| 185 | */ |
||
| 186 | protected $todo = ''; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * data |
||
| 190 | * @var array |
||
| 191 | */ |
||
| 192 | protected $data = array(); |
||
| 193 | |||
| 194 | /** |
||
| 195 | * error handler |
||
| 196 | * @var string |
||
| 197 | */ |
||
| 198 | protected $error = ''; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * database connection |
||
| 202 | * @var string |
||
| 203 | */ |
||
| 204 | protected $database = NULL; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * debug mode |
||
| 208 | * @var boolean |
||
| 209 | */ |
||
| 210 | protected $debugMode = false; |
||
| 211 | |||
| 212 | protected $sunlight; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Render check box |
||
| 216 | * |
||
| 217 | * @param string name |
||
| 218 | * @param mixed value |
||
| 219 | * @param var variable that match with value |
||
| 220 | * @return string html of chceck box |
||
| 221 | */ |
||
| 222 | protected function renderHtmlCheckBox($name, $value, $checked_variable) |
||
| 233 | |||
| 234 | protected function parseTutorEmail($item) |
||
| 249 | |||
| 250 | // zaheshovane udaje, aby se nedali jen tak ziskat data z databaze |
||
| 251 | protected function formKeyHash($id, $meetingId) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @return Model |
||
| 258 | */ |
||
| 259 | protected function getModel() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @param Model $model |
||
| 266 | * @return $this |
||
| 267 | */ |
||
| 268 | protected function setModel($model) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return Container |
||
| 276 | */ |
||
| 277 | protected function getContainer() |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param Container $container |
||
| 284 | * @return $this |
||
| 285 | */ |
||
| 286 | protected function setContainer($container) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return Router |
||
| 294 | */ |
||
| 295 | protected function getRouter() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param Router $router |
||
| 302 | * @return $this |
||
| 303 | */ |
||
| 304 | protected function setRouter($router) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return Latte |
||
| 312 | */ |
||
| 313 | protected function getLatte() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param Latte $latte |
||
| 320 | * @return $this |
||
| 321 | */ |
||
| 322 | protected function setLatte($latte) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | public function getAction($fullyQualified = false) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param string $action |
||
| 338 | * @return $this |
||
| 339 | */ |
||
| 340 | public function setAction($action) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @return SunlightModel |
||
| 348 | */ |
||
| 349 | public function getSunlight() |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param SunlightModel $sunlight |
||
| 360 | * @return $this |
||
| 361 | */ |
||
| 362 | public function setSunlight(SunlightModel $sunlight) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * @return integer |
||
| 370 | */ |
||
| 371 | protected function getMeetingId() |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param integer $meetingId |
||
| 378 | * @return $this |
||
| 379 | */ |
||
| 380 | protected function setMeetingId($meetingId) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @param string $guid |
||
| 388 | * @param array $data |
||
| 389 | * @return ActiveRow |
||
| 390 | */ |
||
| 391 | protected function updateByGuid($guid, array $data) |
||
| 395 | |||
| 396 | public function remember($key, $minutes, \Closure $callback) |
||
| 431 | |||
| 432 | protected function getCache() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @return string |
||
| 439 | */ |
||
| 440 | protected function getDebugMode() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return string |
||
| 447 | */ |
||
| 448 | protected function getBacklink() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @param string $backlink |
||
| 455 | * @return $this |
||
| 456 | */ |
||
| 457 | protected function setBacklink($backlink) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return string |
||
| 466 | */ |
||
| 467 | protected function getBacklinkUrl() |
||
| 478 | |||
| 479 | } |
||
| 480 |
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.