Complex classes like Subscription 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 Subscription, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | final class Subscription extends BaseResource implements Emptiable, Serializable |
||
10 | { |
||
11 | use EmptiableTrait; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | private $profileId; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | private $frequency; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $interval; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $start; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $cycle; |
||
37 | |||
38 | /** |
||
39 | * @var float |
||
40 | */ |
||
41 | private $amount; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $trial; |
||
47 | |||
48 | /** |
||
49 | * @var int |
||
50 | */ |
||
51 | private $trialCycle; |
||
52 | |||
53 | /** |
||
54 | * @var int |
||
55 | */ |
||
56 | private $trialFrequency; |
||
57 | |||
58 | /** |
||
59 | * @var float |
||
60 | */ |
||
61 | private $trialAmount; |
||
62 | |||
63 | /** |
||
64 | * @return int |
||
65 | */ |
||
66 | public function getFrequency() |
||
70 | |||
71 | /** |
||
72 | * @return int |
||
73 | */ |
||
74 | public function getInterval() |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getStart() |
||
86 | |||
87 | /** |
||
88 | * @return int |
||
89 | */ |
||
90 | public function getCycle() |
||
94 | |||
95 | /** |
||
96 | * @return float |
||
97 | */ |
||
98 | public function getAmount() |
||
102 | |||
103 | /** |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function isTrial() |
||
110 | |||
111 | /** |
||
112 | * @return int |
||
113 | */ |
||
114 | public function getTrialCycle() |
||
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | public function getTrialFrequency() |
||
126 | |||
127 | /** |
||
128 | * @return float |
||
129 | */ |
||
130 | public function getTrialAmount() |
||
134 | |||
135 | /** |
||
136 | * @param int $frequency the frequency |
||
137 | */ |
||
138 | public function setFrequency($frequency) |
||
149 | |||
150 | /** |
||
151 | * Sets the value of interval. |
||
152 | */ |
||
153 | public function setInterval($interval) |
||
165 | |||
166 | /** |
||
167 | * @param string $start the start |
||
168 | */ |
||
169 | public function setStart($start) |
||
181 | |||
182 | /** |
||
183 | * @param int $cycle |
||
184 | */ |
||
185 | public function setCycle($cycle) |
||
196 | |||
197 | /** |
||
198 | * @param float $amount |
||
199 | */ |
||
200 | public function setAmount($amount) |
||
206 | |||
207 | /** |
||
208 | * @param bool $trial |
||
209 | */ |
||
210 | public function setTrial($trial) |
||
216 | |||
217 | /** |
||
218 | * @param int $trialCycle |
||
219 | */ |
||
220 | public function setTrialCycle($trialCycle) |
||
231 | |||
232 | /** |
||
233 | * @param int $trialFrequency |
||
234 | */ |
||
235 | public function setTrialFrequency($trialFrequency) |
||
246 | |||
247 | /** |
||
248 | * @param float $trialAmount |
||
249 | */ |
||
250 | public function setTrialAmount($trialAmount) |
||
256 | |||
257 | /** |
||
258 | * @return string |
||
259 | */ |
||
260 | public function getProfileId() |
||
264 | |||
265 | /** |
||
266 | * @param string $profileId |
||
267 | */ |
||
268 | public function setProfileId($profileId) |
||
279 | |||
280 | private function isValidFrequency($frequency) |
||
284 | |||
285 | private function isValidInterval($interval) |
||
296 | |||
297 | private function isValidCycle($cycle) |
||
301 | |||
302 | private function isValidProfileId($profileId) |
||
306 | |||
307 | public function serialize() |
||
326 | } |
||
327 |