Complex classes like BaseMember 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 BaseMember, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class BaseMember implements \JsonSerializable { |
||
| 32 | |||
| 33 | const LEVEL_NONE = 0; |
||
| 34 | const LEVEL_MEMBER = 1; |
||
| 35 | const LEVEL_MODERATOR = 4; |
||
| 36 | const LEVEL_ADMIN = 8; |
||
| 37 | const LEVEL_OWNER = 9; |
||
| 38 | |||
| 39 | const STATUS_NONMEMBER = 'Unknown'; |
||
| 40 | const STATUS_INVITED = 'Invited'; |
||
| 41 | const STATUS_REQUEST = 'Requesting'; |
||
| 42 | const STATUS_MEMBER = 'Member'; |
||
| 43 | const STATUS_BLOCKED = 'Blocked'; |
||
| 44 | const STATUS_KICKED = 'Kicked'; |
||
| 45 | |||
| 46 | /** @var string */ |
||
| 47 | private $circleUniqueId; |
||
| 48 | |||
| 49 | /** @var L10N */ |
||
| 50 | protected $l10n; |
||
| 51 | |||
| 52 | /** @var string */ |
||
| 53 | private $userId = ''; |
||
| 54 | |||
| 55 | /** @var string */ |
||
| 56 | private $groupId = ''; |
||
| 57 | |||
| 58 | /** @var string */ |
||
| 59 | private $displayName; |
||
| 60 | |||
| 61 | /** @var int */ |
||
| 62 | private $level; |
||
| 63 | |||
| 64 | /** @var string */ |
||
| 65 | private $status; |
||
| 66 | |||
| 67 | /** @var string */ |
||
| 68 | private $note; |
||
| 69 | |||
| 70 | /** @var string */ |
||
| 71 | private $joined; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * BaseMember constructor. |
||
| 75 | * |
||
| 76 | * @param $l10n |
||
| 77 | * @param string $userId |
||
| 78 | * @param string $circleUniqueId |
||
| 79 | */ |
||
| 80 | public function __construct($l10n, $userId = '', $circleUniqueId = '') { |
||
| 92 | |||
| 93 | |||
| 94 | /** |
||
| 95 | * @param string $circleUniqueId |
||
| 96 | * |
||
| 97 | * @return $this |
||
| 98 | */ |
||
| 99 | public function setCircleId($circleUniqueId) { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getCircleId() { |
||
| 111 | |||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $groupId |
||
| 115 | */ |
||
| 116 | public function setGroupId($groupId) { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | public function getGroupId() { |
||
| 126 | |||
| 127 | |||
| 128 | public function getViewerType() { |
||
| 135 | |||
| 136 | public function getViewerId() { |
||
| 143 | |||
| 144 | public function setUserId($userId) { |
||
| 157 | |||
| 158 | public function getUserId() { |
||
| 161 | |||
| 162 | |||
| 163 | public function setDisplayName($display) { |
||
| 168 | |||
| 169 | public function getDisplayNAme() { |
||
| 172 | |||
| 173 | |||
| 174 | public function setLevel($level) { |
||
| 179 | |||
| 180 | public function getLevel() { |
||
| 183 | |||
| 184 | |||
| 185 | public function setNote($note) { |
||
| 190 | |||
| 191 | public function getNote() { |
||
| 194 | |||
| 195 | |||
| 196 | public function setStatus($status) { |
||
| 205 | |||
| 206 | public function getStatus() { |
||
| 209 | |||
| 210 | |||
| 211 | public function setJoined($joined) { |
||
| 216 | |||
| 217 | public function getJoined() { |
||
| 220 | |||
| 221 | |||
| 222 | public function isLevel($level) { |
||
| 225 | |||
| 226 | |||
| 227 | public function isAlmostMember() { |
||
| 231 | |||
| 232 | |||
| 233 | protected function setAsAMember($level = 1) { |
||
| 237 | |||
| 238 | |||
| 239 | public static function fromArray($l10n, $arr) { |
||
| 271 | |||
| 272 | |||
| 273 | public static function fromJSON($l10n, $json) { |
||
| 276 | |||
| 277 | public function jsonSerialize() { |
||
| 291 | |||
| 292 | public function getLevelString() { |
||
| 308 | } |
||
| 309 |