Complex classes like SessionWrapper 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 SessionWrapper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class SessionWrapper |
||
| 8 | { |
||
| 9 | /** @var Session **/ |
||
| 10 | protected $currentSession; |
||
| 11 | /** @var RedisManager **/ |
||
| 12 | protected $redisManager; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param RedisManager $redisManager |
||
| 16 | */ |
||
| 17 | public function __construct(RedisManager $redisManager) |
||
| 21 | |||
| 22 | public function setCurrentSession(Session $session) |
||
| 26 | |||
| 27 | public function getCurrentSession() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param int $sessionId |
||
| 34 | * @return Session |
||
| 35 | */ |
||
| 36 | public function createSession($sessionId) |
||
| 45 | |||
| 46 | public function save(Session $session) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $sessionId |
||
| 54 | * @return \Asylamba\Classes\Library\Session\Session |
||
| 55 | */ |
||
| 56 | public function fetchSession($sessionId) |
||
| 65 | |||
| 66 | public function clearWrapper() |
||
| 73 | |||
| 74 | public function add($key, $value) |
||
| 81 | |||
| 82 | public function addBase($key, $id, $name, $sector, $system, $img, $type) |
||
| 89 | |||
| 90 | public function addFlashbag($message, $type) |
||
| 97 | |||
| 98 | public function addHistory($path) |
||
| 105 | |||
| 106 | public function all() |
||
| 113 | |||
| 114 | public function baseExist($id) |
||
| 121 | |||
| 122 | public function clear() |
||
| 129 | |||
| 130 | public function destroy() |
||
| 137 | |||
| 138 | public function exist($key) |
||
| 145 | |||
| 146 | public function flushFlashbags() |
||
| 153 | |||
| 154 | public function getFlashbags() |
||
| 161 | |||
| 162 | public function getHistory() |
||
| 169 | |||
| 170 | public function getLastHistory() |
||
| 177 | |||
| 178 | public function getLifetime() |
||
| 185 | |||
| 186 | public function initLastUpdate() |
||
| 193 | |||
| 194 | public function initPlayerBase() |
||
| 201 | |||
| 202 | public function initPlayerBonus() |
||
| 209 | |||
| 210 | public function initPlayerEvent() |
||
| 217 | |||
| 218 | public function initPlayerInfo() |
||
| 225 | |||
| 226 | public function remove($key) |
||
| 233 | |||
| 234 | public function removeBase($key, $id) |
||
| 241 | |||
| 242 | public function get($key) |
||
| 249 | } |