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) { |
||
168 | |||
169 | public function getCount() { |
||
172 | |||
173 | public function setMembers($members) { |
||
178 | |||
179 | public function getMembers() { |
||
182 | |||
183 | |||
184 | public function toString() { |
||
187 | |||
188 | public function jsonSerialize() { |
||
201 | |||
202 | public static function fromArray($arr) { |
||
233 | |||
234 | public static function TypeString($type) { |
||
250 | |||
251 | public static function TypeLongString($type) { |
||
267 | |||
268 | } |
||
269 | |||
271 |
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker
.