Complex classes like Info 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 Info, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | class Info implements Model |
||
30 | { |
||
31 | protected $totalAccepted; |
||
32 | protected $totalAnswers; |
||
33 | protected $totalBadges; |
||
34 | protected $totalComments; |
||
35 | protected $totalQuestions; |
||
36 | protected $totalUnanswered; |
||
37 | protected $totalUsers; |
||
38 | protected $totalVotes; |
||
39 | protected $answersPerMinute; |
||
40 | protected $apiRevision; |
||
41 | protected $badgesPerMinute; |
||
42 | protected $newActiveUsers; |
||
43 | protected $questionsPerMinute; |
||
44 | protected $site; |
||
45 | |||
46 | public static function fromJson(array $data) |
||
83 | |||
84 | public static function fromProperties( |
||
119 | |||
120 | public function setTotalAccepted($totalAccepted) |
||
126 | |||
127 | public function getTotalAccepted() |
||
131 | |||
132 | public function setTotalAnswers($totalAnswers) |
||
138 | |||
139 | public function getTotalAnswers() |
||
143 | |||
144 | public function setTotalBadges($totalBadges) |
||
150 | |||
151 | public function getTotalBadges() |
||
155 | |||
156 | public function setTotalComments($totalComments) |
||
162 | |||
163 | public function getTotalComments() |
||
167 | |||
168 | public function setTotalQuestions($totalQuestions) |
||
174 | |||
175 | public function getTotalQuestions() |
||
179 | |||
180 | public function setTotalUnanswered($totalUnanswered) |
||
186 | |||
187 | public function getTotalUnanswered() |
||
191 | |||
192 | public function setTotalUsers($totalUsers) |
||
198 | |||
199 | public function getTotalUsers() |
||
203 | |||
204 | public function setTotalVotes($totalVotes) |
||
210 | |||
211 | public function getTotalVotes() |
||
215 | |||
216 | public function setAnswersPerMinute($answersPerMinute) |
||
222 | |||
223 | public function getAnswersPerMinute() |
||
227 | |||
228 | public function setApiRevision($apiRevision) |
||
234 | |||
235 | public function getApiRevision() |
||
239 | |||
240 | public function setBadgesPerMinute($badgesPerMinute) |
||
246 | |||
247 | public function getBadgesPerMinute() |
||
251 | |||
252 | public function setNewActiveUsers($newActiveUsers) |
||
258 | |||
259 | public function getNewActiveUsers() |
||
263 | |||
264 | public function setQuestionsPerMinute($questionsPerMinute) |
||
270 | |||
271 | public function getQuestionsPerMinute() |
||
275 | |||
276 | public function setSite(Site $site = null) |
||
282 | |||
283 | public function getSite() |
||
287 | } |
||
288 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.