Complex classes like ComicFilter 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 ComicFilter, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types = 1); |
||
9 | class ComicFilter |
||
10 | { |
||
11 | /** |
||
12 | * Filter by the issue format (e.g. comic, digital comic, hardcover). |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | public $format; |
||
17 | |||
18 | /** |
||
19 | * Filter by the issue format type (comic or collection). |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $formatType; |
||
24 | |||
25 | /** |
||
26 | * Exclude variants (alternate covers, secondary printings, director's cuts, etc.) from the result set. |
||
27 | * |
||
28 | * @var bool |
||
29 | */ |
||
30 | public $noVariants; |
||
31 | |||
32 | /** |
||
33 | * Return comics within a predefined date range. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | public $dateDescriptor; |
||
38 | |||
39 | /** |
||
40 | * Return comics within a predefined date range. |
||
41 | * Dates must be specified as date1,date2 (e.g. 2013-01-01,2013-01-02). |
||
42 | * Dates are preferably formatted as YYYY-MM-DD but may be sent as any common date format. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | public $dateRange; |
||
47 | |||
48 | /** |
||
49 | * Return only issues in series whose title matches the input. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | public $title; |
||
54 | |||
55 | /** |
||
56 | * Return only issues in series whose title starts with the input. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | public $titleStartsWith; |
||
61 | |||
62 | /** |
||
63 | * Return only issues in series whose start year matches the input. |
||
64 | * |
||
65 | * @var int |
||
66 | */ |
||
67 | public $startYear; |
||
68 | |||
69 | /** |
||
70 | * Return only issues in series whose issue number matches the input. |
||
71 | * |
||
72 | * @var int |
||
73 | */ |
||
74 | public $issueNumber; |
||
75 | |||
76 | /** |
||
77 | * Filter by diamond code. |
||
78 | * |
||
79 | * @var string |
||
80 | */ |
||
81 | public $diamondCode; |
||
82 | |||
83 | /** |
||
84 | * Filter by digital comic id. |
||
85 | * |
||
86 | * @var int |
||
87 | */ |
||
88 | public $digitalId; |
||
89 | |||
90 | /** |
||
91 | * Filter by UPC. |
||
92 | * |
||
93 | * @var string |
||
94 | */ |
||
95 | public $upc; |
||
96 | |||
97 | /** |
||
98 | * Filter by ISBN. |
||
99 | * |
||
100 | * @var string |
||
101 | */ |
||
102 | public $isbn; |
||
103 | |||
104 | /** |
||
105 | * Filter by EAN. |
||
106 | * |
||
107 | * @var string |
||
108 | */ |
||
109 | public $ean; |
||
110 | |||
111 | /** |
||
112 | * Filter by ISSN. |
||
113 | * |
||
114 | * @var string |
||
115 | */ |
||
116 | public $issn; |
||
117 | |||
118 | /** |
||
119 | * Include only results which are available digitally. |
||
120 | * |
||
121 | * @var bool |
||
122 | */ |
||
123 | public $hasDigitalIssue; |
||
124 | |||
125 | /** |
||
126 | * Return only comics which have been modified since the specified date. |
||
127 | * |
||
128 | * @var string |
||
129 | */ |
||
130 | public $modifiedSince; |
||
131 | |||
132 | /** |
||
133 | * Return only comics which feature work by the specified creators |
||
134 | * (accepts a comma-separated list of ids). |
||
135 | * |
||
136 | * @var string |
||
137 | */ |
||
138 | public $creators; |
||
139 | |||
140 | /** |
||
141 | * Return only comics which feature the specified characters |
||
142 | * (accepts a comma-separated list of ids). |
||
143 | * |
||
144 | * @var string |
||
145 | */ |
||
146 | public $characters; |
||
147 | |||
148 | /** |
||
149 | * Return only comics which are part of the specified series |
||
150 | * (accepts a comma-separated list of ids). |
||
151 | * |
||
152 | * @var string |
||
153 | */ |
||
154 | public $series; |
||
155 | |||
156 | /** |
||
157 | * Return only comics which take place in the specified events |
||
158 | * (accepts a comma-separated list of ids). |
||
159 | * |
||
160 | * @var string |
||
161 | */ |
||
162 | public $events; |
||
163 | |||
164 | /** |
||
165 | * Return only comics which contain the specified stories |
||
166 | * (accepts a comma-separated list of ids). |
||
167 | * |
||
168 | * @var string |
||
169 | */ |
||
170 | public $stories; |
||
171 | |||
172 | /** |
||
173 | * Return only comics in which the specified characters appear together |
||
174 | * (for example in which BOTH Spider-Man and Wolverine appear). |
||
175 | * Accepts a comma-separated list of ids. |
||
176 | * |
||
177 | * @var string |
||
178 | */ |
||
179 | public $sharedAppearances; |
||
180 | |||
181 | /** |
||
182 | * Return only comics in which the specified creators worked together |
||
183 | * (for example in which BOTH Stan Lee and Jack Kirby did work). |
||
184 | * Accepts a comma-separated list of ids. |
||
185 | * |
||
186 | * @var string |
||
187 | */ |
||
188 | public $collaborators; |
||
189 | |||
190 | /** |
||
191 | * Order the result set by a field or fields. |
||
192 | * Add a "-" to the value sort in descending order. |
||
193 | * Multiple values are given priority in the order in which they are passed. |
||
194 | * |
||
195 | * @var string |
||
196 | */ |
||
197 | public $orderBy; |
||
198 | |||
199 | /** |
||
200 | * Limit the result set to the specified number of resources. |
||
201 | * |
||
202 | * @var int |
||
203 | */ |
||
204 | public $limit; |
||
205 | |||
206 | /** |
||
207 | * Skip the specified number of resources in the result set. |
||
208 | * |
||
209 | * @var int |
||
210 | */ |
||
211 | public $offset; |
||
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getFormat() |
||
220 | |||
221 | /** |
||
222 | * @param string $format |
||
223 | */ |
||
224 | public function setFormat(string $format) |
||
228 | |||
229 | /** |
||
230 | * @return string |
||
231 | */ |
||
232 | public function getFormatType() |
||
236 | |||
237 | /** |
||
238 | * @param string $formatType |
||
239 | */ |
||
240 | public function setFormatType($formatType) |
||
244 | |||
245 | /** |
||
246 | * @return boolean |
||
247 | */ |
||
248 | public function isNoVariants() |
||
252 | |||
253 | /** |
||
254 | * @param boolean $noVariants |
||
255 | */ |
||
256 | public function setNoVariants($noVariants) |
||
260 | |||
261 | /** |
||
262 | * @return string |
||
263 | */ |
||
264 | public function getDateDescriptor() |
||
268 | |||
269 | /** |
||
270 | * @param string $dateDescriptor |
||
271 | */ |
||
272 | public function setDateDescriptor($dateDescriptor) |
||
276 | |||
277 | /** |
||
278 | * @return int |
||
279 | */ |
||
280 | public function getDateRange() |
||
284 | |||
285 | /** |
||
286 | * @param int $dateRange |
||
287 | */ |
||
288 | public function setDateRange($dateRange) |
||
292 | |||
293 | /** |
||
294 | * @return string |
||
295 | */ |
||
296 | public function getTitle() |
||
300 | |||
301 | /** |
||
302 | * @param string $title |
||
303 | */ |
||
304 | public function setTitle(string $title) |
||
308 | |||
309 | /** |
||
310 | * @return string |
||
311 | */ |
||
312 | public function getTitleStartsWith() |
||
316 | |||
317 | /** |
||
318 | * @param string $titleStartsWith |
||
319 | */ |
||
320 | public function setTitleStartsWith(string $titleStartsWith) |
||
324 | |||
325 | /** |
||
326 | * @return int |
||
327 | */ |
||
328 | public function getStartYear() |
||
332 | |||
333 | /** |
||
334 | * @param int $startYear |
||
335 | */ |
||
336 | public function setStartYear(int $startYear) |
||
340 | |||
341 | /** |
||
342 | * @return int |
||
343 | */ |
||
344 | public function getIssueNumber() |
||
348 | |||
349 | /** |
||
350 | * @param int $issueNumber |
||
351 | */ |
||
352 | public function setIssueNumber(int $issueNumber) |
||
356 | |||
357 | /** |
||
358 | * @return string |
||
359 | */ |
||
360 | public function getDiamondCode() |
||
364 | |||
365 | /** |
||
366 | * @param string $diamondCode |
||
367 | */ |
||
368 | public function setDiamondCode(string $diamondCode) |
||
372 | |||
373 | /** |
||
374 | * @return int |
||
375 | */ |
||
376 | public function getDigitalId() |
||
380 | |||
381 | /** |
||
382 | * @param int $digitalId |
||
383 | */ |
||
384 | public function setDigitalId(int $digitalId) |
||
388 | |||
389 | /** |
||
390 | * @return string |
||
391 | */ |
||
392 | public function getUpc() |
||
396 | |||
397 | /** |
||
398 | * @param string $upc |
||
399 | */ |
||
400 | public function setUpc(string $upc) |
||
404 | |||
405 | /** |
||
406 | * @return string |
||
407 | */ |
||
408 | public function getIsbn() |
||
412 | |||
413 | /** |
||
414 | * @param string $isbn |
||
415 | */ |
||
416 | public function setIsbn(string $isbn) |
||
420 | |||
421 | /** |
||
422 | * @return string |
||
423 | */ |
||
424 | public function getEan() |
||
428 | |||
429 | /** |
||
430 | * @param string $ean |
||
431 | */ |
||
432 | public function setEan(string $ean) |
||
436 | |||
437 | /** |
||
438 | * @return string |
||
439 | */ |
||
440 | public function getIssn() |
||
444 | |||
445 | /** |
||
446 | * @param string $issn |
||
447 | */ |
||
448 | public function setIssn(string $issn) |
||
452 | |||
453 | /** |
||
454 | * @return boolean |
||
455 | */ |
||
456 | public function isHasDigitalIssue() |
||
460 | |||
461 | /** |
||
462 | * @param boolean $hasDigitalIssue |
||
463 | */ |
||
464 | public function setHasDigitalIssue(bool $hasDigitalIssue) |
||
468 | |||
469 | /** |
||
470 | * @return string |
||
471 | */ |
||
472 | public function getModifiedSince() |
||
476 | |||
477 | /** |
||
478 | * @param string $modifiedSince |
||
479 | */ |
||
480 | public function setModifiedSince(string $modifiedSince) |
||
484 | |||
485 | /** |
||
486 | * @return int |
||
487 | */ |
||
488 | public function getCreators() |
||
492 | |||
493 | /** |
||
494 | * @param string $creators |
||
495 | */ |
||
496 | public function setCreators(string $creators) |
||
500 | |||
501 | /** |
||
502 | * @return string |
||
503 | */ |
||
504 | public function getCharacters() |
||
508 | |||
509 | /** |
||
510 | * @param string $characters |
||
511 | */ |
||
512 | public function setCharacters(string $characters) |
||
516 | |||
517 | /** |
||
518 | * @return string |
||
519 | */ |
||
520 | public function getSeries() |
||
524 | |||
525 | /** |
||
526 | * @param string $series |
||
527 | */ |
||
528 | public function setSeries(string $series) |
||
532 | |||
533 | /** |
||
534 | * @return string |
||
535 | */ |
||
536 | public function getEvents() |
||
540 | |||
541 | /** |
||
542 | * @param string $events |
||
543 | */ |
||
544 | public function setEvents(string $events) |
||
548 | |||
549 | /** |
||
550 | * @return string |
||
551 | */ |
||
552 | public function getStories() |
||
556 | |||
557 | /** |
||
558 | * @param string $stories |
||
559 | */ |
||
560 | public function setStories(string $stories) |
||
564 | |||
565 | /** |
||
566 | * @return string |
||
567 | */ |
||
568 | public function getSharedAppearances() |
||
572 | |||
573 | /** |
||
574 | * @param string $sharedAppearances |
||
575 | */ |
||
576 | public function setSharedAppearances(string $sharedAppearances) |
||
580 | |||
581 | /** |
||
582 | * @return string |
||
583 | */ |
||
584 | public function getCollaborators() |
||
588 | |||
589 | /** |
||
590 | * @param string $collaborators |
||
591 | */ |
||
592 | public function setCollaborators(string $collaborators) |
||
596 | |||
597 | /** |
||
598 | * @return string |
||
599 | */ |
||
600 | public function getOrderBy() |
||
604 | |||
605 | /** |
||
606 | * @param string $orderBy |
||
607 | */ |
||
608 | public function setOrderBy(string $orderBy) |
||
612 | |||
613 | /** |
||
614 | * @return int |
||
615 | */ |
||
616 | public function getLimit() |
||
620 | |||
621 | /** |
||
622 | * @param int $limit |
||
623 | */ |
||
624 | public function setLimit(int $limit) |
||
628 | |||
629 | /** |
||
630 | * @return int |
||
631 | */ |
||
632 | public function getOffset() |
||
636 | |||
637 | /** |
||
638 | * @param int $offset |
||
639 | */ |
||
640 | public function setOffset(int $offset) |
||
644 | } |
||
645 |