Complex classes like Video 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 Video, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Video implements VideoInterface |
||
13 | { |
||
14 | /** |
||
15 | * @Type("string") |
||
16 | */ |
||
17 | private $id; |
||
18 | |||
19 | /** |
||
20 | * @Type("string") |
||
21 | */ |
||
22 | private $title; |
||
23 | |||
24 | /** |
||
25 | * @Type("string") |
||
26 | */ |
||
27 | private $description; |
||
28 | |||
29 | /** |
||
30 | * @Type("string") |
||
31 | */ |
||
32 | private $thumbnail; |
||
33 | |||
34 | /** |
||
35 | * @Type("integer") |
||
36 | */ |
||
37 | private $length; |
||
38 | |||
39 | /** |
||
40 | * @Type("integer") |
||
41 | * @SerializedName("createdDate") |
||
42 | */ |
||
43 | private $createdDate; |
||
44 | |||
45 | /** |
||
46 | * @Type("integer") |
||
47 | * @SerializedName("modifiedDate") |
||
48 | */ |
||
49 | private $modifiedDate; |
||
50 | |||
51 | /** |
||
52 | * @Type("integer") |
||
53 | * @SerializedName("uploadDate") |
||
54 | */ |
||
55 | private $uploadDate; |
||
56 | |||
57 | /** |
||
58 | * @Type("integer") |
||
59 | */ |
||
60 | private $generation; |
||
61 | |||
62 | /** |
||
63 | * @Type("integer") |
||
64 | */ |
||
65 | private $plays; |
||
66 | |||
67 | /** |
||
68 | * @Type("integer") |
||
69 | */ |
||
70 | private $views; |
||
71 | |||
72 | /** |
||
73 | * @Type("boolean") |
||
74 | * @SerializedName("allFormatsAvailable") |
||
75 | */ |
||
76 | private $allFormatsAvailable; |
||
77 | |||
78 | /** |
||
79 | * @TODO replace it with array collection |
||
80 | * |
||
81 | * @Type("array") |
||
82 | * @SerializedName("customMetadata") |
||
83 | */ |
||
84 | private $customMetadata; |
||
85 | |||
86 | /** |
||
87 | * @TODO replace it with array collection |
||
88 | * |
||
89 | * @Type("array") |
||
90 | */ |
||
91 | private $keywords; |
||
92 | |||
93 | /** |
||
94 | * @TODO replace it with array collection |
||
95 | * |
||
96 | * @Type("array") |
||
97 | */ |
||
98 | private $stills; |
||
99 | |||
100 | /** |
||
101 | * @Type("boolean") |
||
102 | */ |
||
103 | private $published; |
||
104 | |||
105 | /** |
||
106 | * @Type("array") |
||
107 | */ |
||
108 | private $channels; |
||
109 | |||
110 | /** |
||
111 | * @Type("string") |
||
112 | * @SerializedName("uploadFileName") |
||
113 | */ |
||
114 | private $uploadFileName; |
||
115 | |||
116 | /** |
||
117 | * @Type("boolean") |
||
118 | */ |
||
119 | private $downloadable; |
||
120 | |||
121 | /** |
||
122 | * @Type("MovingImage\Client\VMPro\Entity\CorporateTubeMetaData") |
||
123 | * @SerializedName("corporateTubeMetadata") |
||
124 | */ |
||
125 | private $corporateTubeMetadata; |
||
126 | |||
127 | public function setId(string $id): self |
||
133 | |||
134 | public function getId(): string |
||
138 | |||
139 | public function getTitle(): ?string |
||
143 | |||
144 | public function setTitle(string $title): self |
||
150 | |||
151 | public function getDescription(): ?string |
||
155 | |||
156 | public function setDescription(string $description): self |
||
162 | |||
163 | public function getThumbnail(): ?string |
||
167 | |||
168 | public function setThumbnail(string $thumbnail): self |
||
174 | |||
175 | public function getLength(): ?int |
||
179 | |||
180 | public function setLength(int $length): self |
||
186 | |||
187 | public function getCreatedDate(): DateTime |
||
194 | |||
195 | public function setCreatedDate(DateTime $createdDate): Video |
||
201 | |||
202 | public function getModifiedDate(): ?DateTime |
||
209 | |||
210 | public function setModifiedDate(DateTime $modifiedDate): self |
||
216 | |||
217 | public function getUploadDate(): ?DateTime |
||
224 | |||
225 | public function setUploadDate(DateTime $uploadDate): self |
||
231 | |||
232 | public function getGeneration(): ?int |
||
236 | |||
237 | public function setGeneration(int $generation): self |
||
243 | |||
244 | public function getPlays(): int |
||
252 | |||
253 | public function setPlays(int $plays): self |
||
259 | |||
260 | public function getViews(): int |
||
268 | |||
269 | public function setViews(int $views): self |
||
275 | |||
276 | public function areAllFormatsAvailable(): bool |
||
284 | |||
285 | public function setAllFormatsAvailable(bool $allFormatsAvailable): self |
||
291 | |||
292 | public function getCustomMetadata(): array |
||
300 | |||
301 | public function setCustomMetadata(array $customMetadata): self |
||
307 | |||
308 | public function getKeywords(): array |
||
316 | |||
317 | public function setKeywords(array $keywords): self |
||
323 | |||
324 | public function getStills(): array |
||
341 | |||
342 | public function setStills(array $stills): self |
||
348 | |||
349 | public function setPublished(bool $published): self |
||
355 | |||
356 | public function isPublished(): bool |
||
364 | |||
365 | public function setDownloadable(bool $downloadable): self |
||
371 | |||
372 | public function isDownloadable(): bool |
||
380 | |||
381 | public function getStatus(): int |
||
387 | |||
388 | public function getChannels(): array |
||
397 | |||
398 | public function setChannels(array $channels): self |
||
404 | |||
405 | public function getUploadFileName(): string |
||
413 | |||
414 | public function setUploadFileName(string $uploadFileName): self |
||
420 | |||
421 | public function setCorporateTubeMetadata(CorporateTubeMetaData $corporateTubeMetadata): self |
||
427 | |||
428 | public function getCorporateTubeMetadata(): ?CorporateTubeMetaData |
||
432 | } |
||
433 |