Complex classes like View 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 View, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class View extends Model |
||
8 | { |
||
9 | /** |
||
10 | * @var integer |
||
11 | */ |
||
12 | protected $id; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $uuid; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $ymClientId; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $gaClientId; |
||
28 | |||
29 | /** |
||
30 | * @var integer |
||
31 | */ |
||
32 | protected $projectId; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $source; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $campaign; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $keyword; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $seoSystem; |
||
53 | |||
54 | /** |
||
55 | * @var Visitor|null |
||
56 | */ |
||
57 | protected $visitor; |
||
58 | |||
59 | /** |
||
60 | * @var Visitor|null |
||
61 | */ |
||
62 | protected $realVisitor; |
||
63 | |||
64 | public function __construct(array $viewData = []) |
||
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | * @throws LPTrackerSDKException |
||
104 | */ |
||
105 | public function validate() |
||
119 | |||
120 | /** |
||
121 | * @return array |
||
122 | */ |
||
123 | public function toArray() |
||
160 | |||
161 | /** |
||
162 | * @return int |
||
163 | */ |
||
164 | public function getId() |
||
168 | |||
169 | /** |
||
170 | * @return int |
||
171 | */ |
||
172 | public function getProjectId() |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getSource() |
||
184 | |||
185 | /** |
||
186 | * @param string $source |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function setSource($source) |
||
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getCampaign() |
||
202 | |||
203 | /** |
||
204 | * @param string $campaign |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function setCampaign($campaign) |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getKeyword() |
||
220 | |||
221 | /** |
||
222 | * @param string $keyword |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function setKeyword($keyword) |
||
230 | |||
231 | /** |
||
232 | * @return string |
||
233 | */ |
||
234 | public function getSeoSystem() |
||
238 | |||
239 | /** |
||
240 | * @param string $seoSystem |
||
241 | * @return $this |
||
242 | */ |
||
243 | public function setSeoSystem($seoSystem) |
||
248 | |||
249 | /** |
||
250 | * @return string |
||
251 | */ |
||
252 | public function getUuid() |
||
256 | |||
257 | /** |
||
258 | * @return string |
||
259 | */ |
||
260 | public function getYmClientId() |
||
264 | |||
265 | /** |
||
266 | * @return string |
||
267 | */ |
||
268 | public function getGaClientId() |
||
272 | |||
273 | /** |
||
274 | * @return Visitor|null |
||
275 | */ |
||
276 | public function getVisitor() |
||
280 | |||
281 | /** |
||
282 | * @return Visitor|null |
||
283 | */ |
||
284 | public function getRealVisitor() |
||
288 | } |
||
289 |