Complex classes like TimeEntry 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 TimeEntry, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
11 | class TimeEntry |
||
12 | { |
||
13 | /** |
||
14 | * @var integer |
||
15 | */ |
||
16 | private $id; |
||
17 | |||
18 | /** |
||
19 | * @var integer |
||
20 | */ |
||
21 | private $pid; |
||
22 | |||
23 | /** |
||
24 | * @var integer |
||
25 | */ |
||
26 | private $tid; |
||
27 | |||
28 | /** |
||
29 | * @var integer |
||
30 | */ |
||
31 | private $uid; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $description; |
||
37 | |||
38 | /** |
||
39 | * @var \DateTime |
||
40 | */ |
||
41 | private $start; |
||
42 | |||
43 | /** |
||
44 | * @var \DateTime |
||
45 | */ |
||
46 | private $end; |
||
47 | |||
48 | /** |
||
49 | * @var \DateTime |
||
50 | */ |
||
51 | private $updated; |
||
52 | |||
53 | /** |
||
54 | * @var integer |
||
55 | */ |
||
56 | private $duration; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | private $user; |
||
62 | |||
63 | /** |
||
64 | * @var boolean |
||
65 | */ |
||
66 | private $useStop; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | private $client; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | private $project; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | private $projectColor; |
||
82 | |||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | private $projectHexColor; |
||
87 | |||
88 | /** |
||
89 | * @var string |
||
90 | */ |
||
91 | private $task; |
||
92 | |||
93 | /** |
||
94 | * @var string |
||
95 | */ |
||
96 | private $billableText; |
||
97 | |||
98 | /** |
||
99 | * @var boolean |
||
100 | */ |
||
101 | private $billable; |
||
102 | |||
103 | /** |
||
104 | * @var string |
||
105 | */ |
||
106 | private $cur; |
||
107 | |||
108 | /** |
||
109 | * @var array |
||
110 | */ |
||
111 | private $tags; |
||
112 | |||
113 | /** |
||
114 | * @return int |
||
115 | */ |
||
116 | public function getId(): int |
||
120 | |||
121 | /** |
||
122 | * @param int $id |
||
123 | */ |
||
124 | public function setId(int $id) |
||
128 | |||
129 | /** |
||
130 | * @return int |
||
131 | */ |
||
132 | public function getPid(): int |
||
136 | |||
137 | /** |
||
138 | * @param int $pid |
||
139 | */ |
||
140 | public function setPid(int $pid) |
||
144 | |||
145 | /** |
||
146 | * @return int |
||
147 | */ |
||
148 | public function getTid(): int |
||
152 | |||
153 | /** |
||
154 | * @param int $tid |
||
155 | */ |
||
156 | public function setTid(int $tid) |
||
160 | |||
161 | /** |
||
162 | * @return int |
||
163 | */ |
||
164 | public function getUid(): int |
||
168 | |||
169 | /** |
||
170 | * @param int $uid |
||
171 | */ |
||
172 | public function setUid(int $uid) |
||
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getDescription(): string |
||
184 | |||
185 | /** |
||
186 | * @param string $description |
||
187 | */ |
||
188 | public function setDescription(string $description) |
||
192 | |||
193 | /** |
||
194 | * @return \DateTime |
||
195 | */ |
||
196 | public function getStart(): \DateTime |
||
200 | |||
201 | /** |
||
202 | * @param \DateTime $start |
||
203 | */ |
||
204 | public function setStart(\DateTime $start) |
||
208 | |||
209 | /** |
||
210 | * @return \DateTime |
||
211 | */ |
||
212 | public function getEnd(): \DateTime |
||
216 | |||
217 | /** |
||
218 | * @param \DateTime $end |
||
219 | */ |
||
220 | public function setEnd(\DateTime $end) |
||
224 | |||
225 | /** |
||
226 | * @return \DateTime |
||
227 | */ |
||
228 | public function getUpdated(): \DateTime |
||
232 | |||
233 | /** |
||
234 | * @param \DateTime $updated |
||
235 | */ |
||
236 | public function setUpdated(\DateTime $updated) |
||
240 | |||
241 | /** |
||
242 | * @return int |
||
243 | */ |
||
244 | public function getDuration(): int |
||
248 | |||
249 | /** |
||
250 | * @param int $duration |
||
251 | */ |
||
252 | public function setDuration(int $duration) |
||
256 | |||
257 | /** |
||
258 | * @return string |
||
259 | */ |
||
260 | public function getUser(): string |
||
264 | |||
265 | /** |
||
266 | * @param string $user |
||
267 | */ |
||
268 | public function setUser(string $user) |
||
272 | |||
273 | /** |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function isUseStop(): bool |
||
280 | |||
281 | /** |
||
282 | * @param bool $useStop |
||
283 | */ |
||
284 | public function setUseStop(bool $useStop) |
||
288 | |||
289 | /** |
||
290 | * @return string |
||
291 | */ |
||
292 | public function getClient(): string |
||
296 | |||
297 | /** |
||
298 | * @param string $client |
||
299 | */ |
||
300 | public function setClient(string $client) |
||
304 | |||
305 | /** |
||
306 | * @return string |
||
307 | */ |
||
308 | public function getProject(): string |
||
312 | |||
313 | /** |
||
314 | * @param string $project |
||
315 | */ |
||
316 | public function setProject(string $project) |
||
320 | |||
321 | /** |
||
322 | * @return string |
||
323 | */ |
||
324 | public function getProjectColor(): string |
||
328 | |||
329 | /** |
||
330 | * @param string $projectColor |
||
331 | */ |
||
332 | public function setProjectColor(string $projectColor) |
||
336 | |||
337 | /** |
||
338 | * @return string |
||
339 | */ |
||
340 | public function getProjectHexColor(): string |
||
344 | |||
345 | /** |
||
346 | * @param string $projectHexColor |
||
347 | */ |
||
348 | public function setProjectHexColor(string $projectHexColor) |
||
352 | |||
353 | /** |
||
354 | * @return string |
||
355 | */ |
||
356 | public function getTask(): string |
||
360 | |||
361 | /** |
||
362 | * @param string $task |
||
363 | */ |
||
364 | public function setTask(string $task) |
||
368 | |||
369 | /** |
||
370 | * @return string |
||
371 | */ |
||
372 | public function getBillableText(): string |
||
376 | |||
377 | /** |
||
378 | * @param string $billableText |
||
379 | */ |
||
380 | public function setBillableText(string $billableText) |
||
384 | |||
385 | /** |
||
386 | * @return bool |
||
387 | */ |
||
388 | public function isBillable(): bool |
||
392 | |||
393 | /** |
||
394 | * @param bool $billable |
||
395 | */ |
||
396 | public function setBillable(bool $billable) |
||
400 | |||
401 | /** |
||
402 | * @return string |
||
403 | */ |
||
404 | public function getCur(): string |
||
408 | |||
409 | /** |
||
410 | * @param string $cur |
||
411 | */ |
||
412 | public function setCur(string $cur) |
||
416 | |||
417 | /** |
||
418 | * @return array |
||
419 | */ |
||
420 | public function getTags(): array |
||
424 | |||
425 | /** |
||
426 | * @param array $tags |
||
427 | */ |
||
428 | public function setTags(array $tags) |
||
432 | } |
||
433 |