Complex classes like SessionHistoryDecorator 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 SessionHistoryDecorator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class SessionHistoryDecorator extends Session |
||
| 34 | { |
||
| 35 | use ModuleAwareTrait; |
||
| 36 | |||
| 37 | public $sessionHistoryTable = '{{%session_history}}'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var Session |
||
| 41 | */ |
||
| 42 | public $session; |
||
| 43 | |||
| 44 | public $condition; |
||
| 45 | |||
| 46 | public function __construct( |
||
| 56 | |||
| 57 | /** @inheritdoc */ |
||
| 58 | public function getUseCustomStorage() |
||
| 62 | |||
| 63 | /** @inheritdoc */ |
||
| 64 | public function getIsActive() |
||
| 68 | |||
| 69 | /** @inheritdoc */ |
||
| 70 | public function getHasSessionId() |
||
| 74 | |||
| 75 | /** @inheritdoc */ |
||
| 76 | public function setHasSessionId($value) |
||
| 80 | |||
| 81 | /** @inheritdoc */ |
||
| 82 | public function getId() |
||
| 86 | |||
| 87 | /** @inheritdoc */ |
||
| 88 | public function setId($value) |
||
| 92 | |||
| 93 | /** @inheritdoc */ |
||
| 94 | public function regenerateID($deleteOldSession = false) |
||
| 120 | |||
| 121 | /** @inheritdoc */ |
||
| 122 | public function getName() |
||
| 126 | |||
| 127 | /** @inheritdoc */ |
||
| 128 | public function setName($value) |
||
| 132 | |||
| 133 | /** @inheritdoc */ |
||
| 134 | public function getSavePath() |
||
| 138 | |||
| 139 | /** @inheritdoc */ |
||
| 140 | public function setSavePath($value) |
||
| 144 | |||
| 145 | /** @inheritdoc */ |
||
| 146 | public function getCookieParams() |
||
| 150 | |||
| 151 | /** @inheritdoc */ |
||
| 152 | public function setCookieParams(array $value) |
||
| 156 | |||
| 157 | /** @inheritdoc */ |
||
| 158 | public function getUseCookies() |
||
| 162 | |||
| 163 | /** @inheritdoc */ |
||
| 164 | public function setUseCookies($value) |
||
| 168 | |||
| 169 | /** @inheritdoc */ |
||
| 170 | public function getGCProbability() |
||
| 174 | |||
| 175 | /** @inheritdoc */ |
||
| 176 | public function setGCProbability($value) |
||
| 180 | |||
| 181 | /** @inheritdoc */ |
||
| 182 | public function getUseTransparentSessionID() |
||
| 186 | |||
| 187 | /** @inheritdoc */ |
||
| 188 | public function setUseTransparentSessionID($value) |
||
| 192 | |||
| 193 | /** @inheritdoc */ |
||
| 194 | public function getTimeout() |
||
| 198 | |||
| 199 | /** @inheritdoc */ |
||
| 200 | public function setTimeout($value) |
||
| 204 | |||
| 205 | /** @inheritdoc */ |
||
| 206 | public function openSession($savePath, $sessionName) |
||
| 210 | |||
| 211 | /** @inheritdoc */ |
||
| 212 | public function closeSession() |
||
| 216 | |||
| 217 | /** @inheritdoc */ |
||
| 218 | public function readSession($id) |
||
| 222 | |||
| 223 | /** @inheritdoc */ |
||
| 224 | public function writeSession($id, $data) |
||
| 260 | |||
| 261 | /** @inheritdoc */ |
||
| 262 | public function destroySession($id) |
||
| 274 | |||
| 275 | /** @inheritdoc */ |
||
| 276 | public function gcSession($maxLifetime) |
||
| 291 | |||
| 292 | /** @inheritdoc */ |
||
| 293 | public function getIterator() |
||
| 297 | |||
| 298 | /** @inheritdoc */ |
||
| 299 | public function getCount() |
||
| 303 | |||
| 304 | /** @inheritdoc */ |
||
| 305 | public function count() |
||
| 309 | |||
| 310 | /** @inheritdoc */ |
||
| 311 | public function remove($key) |
||
| 315 | |||
| 316 | /** @inheritdoc */ |
||
| 317 | public function removeAll() |
||
| 321 | |||
| 322 | /** @inheritdoc */ |
||
| 323 | public function has($key) |
||
| 327 | |||
| 328 | /** @inheritdoc */ |
||
| 329 | public function getFlash($key, $defaultValue = null, $delete = false) |
||
| 333 | |||
| 334 | /** @inheritdoc */ |
||
| 335 | public function getAllFlashes($delete = false) |
||
| 339 | |||
| 340 | /** @inheritdoc */ |
||
| 341 | public function setFlash($key, $value = true, $removeAfterAccess = true) |
||
| 345 | |||
| 346 | /** @inheritdoc */ |
||
| 347 | public function addFlash($key, $value = true, $removeAfterAccess = true) |
||
| 351 | |||
| 352 | /** @inheritdoc */ |
||
| 353 | public function removeFlash($key) |
||
| 357 | |||
| 358 | /** @inheritdoc */ |
||
| 359 | public function removeAllFlashes() |
||
| 363 | |||
| 364 | /** @inheritdoc */ |
||
| 365 | public function hasFlash($key) |
||
| 369 | |||
| 370 | /** @inheritdoc */ |
||
| 371 | public function offsetExists($offset) |
||
| 375 | |||
| 376 | /** @inheritdoc */ |
||
| 377 | public function offsetGet($offset) |
||
| 381 | |||
| 382 | /** @inheritdoc */ |
||
| 383 | public function offsetSet($offset, $item) |
||
| 387 | |||
| 388 | /** @inheritdoc */ |
||
| 389 | public function offsetUnset($offset) |
||
| 393 | |||
| 394 | /** @inheritdoc */ |
||
| 395 | public function setCacheLimiter($cacheLimiter) |
||
| 399 | |||
| 400 | /** @inheritdoc */ |
||
| 401 | public function getCacheLimiter() |
||
| 405 | |||
| 406 | /** |
||
| 407 | * @param string $id |
||
| 408 | * @return bool |
||
| 409 | * @throws Exception |
||
| 410 | */ |
||
| 411 | protected function unbindSessionHistory($id) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * |
||
| 422 | * @param int $userId |
||
| 423 | * @return bool |
||
| 424 | * @throws Exception |
||
| 425 | */ |
||
| 426 | protected function displacementHistory($userId) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @return SessionHistoryQuery |
||
| 451 | */ |
||
| 452 | protected function getHistoryQuery() |
||
| 456 | |||
| 457 | protected function getDb() |
||
| 461 | } |