Complex classes like Circle 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 Circle, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class Circle implements \JsonSerializable { |
||
30 | |||
31 | const CIRCLES_PERSONAL = 1; |
||
32 | const CIRCLES_HIDDEN = 2; |
||
33 | const CIRCLES_PRIVATE = 4; |
||
34 | const CIRCLES_PUBLIC = 8; |
||
35 | |||
36 | const CIRCLES_ALL = 15; |
||
37 | |||
38 | private $id; |
||
39 | private $name; |
||
40 | |||
41 | /** @var Member */ |
||
42 | private $owner; |
||
43 | |||
44 | /** @var Member */ |
||
45 | private $user; |
||
46 | private $description; |
||
47 | private $type; |
||
48 | private $typeString; |
||
49 | private $typeLongString; |
||
50 | private $creation; |
||
51 | private $count; |
||
|
|||
52 | private $members; |
||
53 | private $info; |
||
54 | |||
55 | public function __construct() { |
||
58 | |||
59 | |||
60 | public function setId($id) { |
||
65 | |||
66 | public function getId() { |
||
69 | |||
70 | |||
71 | public function setName($name) { |
||
76 | |||
77 | public function getName() { |
||
80 | |||
81 | |||
82 | public function getOwner() { |
||
85 | |||
86 | public function setOwner($owner) { |
||
89 | |||
90 | |||
91 | public function getUser() { |
||
94 | |||
95 | public function setUser($user) { |
||
98 | |||
99 | |||
100 | public function setDescription($description) { |
||
105 | |||
106 | public function getDescription() { |
||
109 | |||
110 | |||
111 | public function setType($type) { |
||
119 | |||
120 | public function getType() { |
||
123 | |||
124 | public function setTypeString($str) { |
||
129 | |||
130 | public function getTypeString() { |
||
133 | |||
134 | public function setTypeLongString($str) { |
||
137 | |||
138 | public function getTypeLongString() { |
||
141 | |||
142 | |||
143 | public function setInfo($str) { |
||
146 | |||
147 | public function getInfo() { |
||
150 | |||
151 | |||
152 | public function setCreation($creation) { |
||
157 | |||
158 | public function getCreation() { |
||
161 | |||
162 | |||
163 | // public function setCount($count) { |
||
164 | // $this->count = $count; |
||
165 | // |
||
166 | // return $this; |
||
167 | // } |
||
168 | // |
||
169 | // public function getCount() { |
||
170 | // return $this->count; |
||
171 | // } |
||
172 | |||
173 | public function setMembers($members) { |
||
178 | |||
179 | public function getMembers() { |
||
182 | |||
183 | |||
184 | public function toString() { |
||
187 | |||
188 | public function jsonSerialize() { |
||
200 | |||
201 | public static function fromArray($arr) { |
||
218 | |||
219 | |||
220 | /** |
||
221 | * return Owner Infos from Array |
||
222 | * |
||
223 | * @param $array |
||
224 | * |
||
225 | * @return null|Member |
||
226 | */ |
||
227 | private static function getOwnerMemberFromArray($array) { |
||
237 | |||
238 | /** |
||
239 | * return User Infos from Array |
||
240 | * |
||
241 | * @param $array |
||
242 | * |
||
243 | * @return null|Member |
||
244 | */ |
||
245 | private static function getUserMemberFromArray($array) { |
||
261 | |||
262 | |||
263 | public static function TypeString($type) { |
||
279 | |||
280 | /** |
||
281 | * @param $type |
||
282 | * |
||
283 | * @return string |
||
284 | */ |
||
285 | public static function TypeLongString($type) { |
||
301 | |||
302 | } |
||
303 | |||
305 |
This check marks private properties in classes that are never used. Those properties can be removed.