Complex classes like AndroidNotification 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 AndroidNotification, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class AndroidNotification implements FcmResource |
||
6 | { |
||
7 | /** |
||
8 | * @var string|null |
||
9 | */ |
||
10 | protected $title; |
||
11 | |||
12 | /** |
||
13 | * @var string|null |
||
14 | */ |
||
15 | protected $body; |
||
16 | |||
17 | /** |
||
18 | * @var string|null |
||
19 | */ |
||
20 | protected $icon; |
||
21 | |||
22 | /** |
||
23 | * @var string|null |
||
24 | */ |
||
25 | protected $color; |
||
26 | |||
27 | /** |
||
28 | * @var string|null |
||
29 | */ |
||
30 | protected $sound; |
||
31 | |||
32 | /** |
||
33 | * @var string|null |
||
34 | */ |
||
35 | protected $tag; |
||
36 | |||
37 | /** |
||
38 | * @var string|null |
||
39 | */ |
||
40 | protected $clickAction; |
||
41 | |||
42 | /** |
||
43 | * @var string|null |
||
44 | */ |
||
45 | protected $bodyLocKey; |
||
46 | |||
47 | /** |
||
48 | * @var string[]|null |
||
49 | */ |
||
50 | protected $bodyLocArgs; |
||
51 | |||
52 | /** |
||
53 | * @var string|null |
||
54 | */ |
||
55 | protected $titleLocKey; |
||
56 | |||
57 | /** |
||
58 | * @var string[]|null |
||
59 | */ |
||
60 | protected $titleLocArgs; |
||
61 | |||
62 | /** |
||
63 | * @var string|null |
||
64 | */ |
||
65 | protected $channelId; |
||
66 | |||
67 | /** |
||
68 | * @var string|null |
||
69 | */ |
||
70 | protected $ticker; |
||
71 | |||
72 | /** |
||
73 | * @var bool|null |
||
74 | */ |
||
75 | protected $sticky; |
||
76 | |||
77 | /** |
||
78 | * @var string|null |
||
79 | */ |
||
80 | protected $eventTime; |
||
81 | |||
82 | /** |
||
83 | * @var bool|null |
||
84 | */ |
||
85 | protected $localOnly; |
||
86 | |||
87 | /** |
||
88 | * @var NotificationPriority|null |
||
89 | */ |
||
90 | protected $notificationPriority; |
||
91 | |||
92 | /** |
||
93 | * @var bool|null |
||
94 | */ |
||
95 | protected $defaultSound; |
||
96 | |||
97 | /** |
||
98 | * @var bool|null |
||
99 | */ |
||
100 | protected $defaultVibrateTimings; |
||
101 | |||
102 | /** |
||
103 | * @var bool|null |
||
104 | */ |
||
105 | protected $defaultLightSettings; |
||
106 | |||
107 | /** |
||
108 | * @var string[]|null |
||
109 | */ |
||
110 | protected $vibrateTimings; |
||
111 | |||
112 | /** |
||
113 | * @var Visibility|null |
||
114 | */ |
||
115 | protected $visibility; |
||
116 | |||
117 | /** |
||
118 | * @var int|null |
||
119 | */ |
||
120 | protected $notificationCount; |
||
121 | |||
122 | /** |
||
123 | * @var LightSettings|null |
||
124 | */ |
||
125 | protected $lightSettings; |
||
126 | |||
127 | /** |
||
128 | * @var string|null |
||
129 | */ |
||
130 | protected $image; |
||
131 | |||
132 | /** |
||
133 | * @return static |
||
134 | */ |
||
135 | public static function create(): self |
||
139 | |||
140 | /** |
||
141 | * @return string|null |
||
142 | */ |
||
143 | public function getTitle(): ?string |
||
147 | |||
148 | /** |
||
149 | * @param string|null $title |
||
150 | * @return AndroidNotification |
||
151 | */ |
||
152 | public function setTitle(?string $title): self |
||
158 | |||
159 | /** |
||
160 | * @return string|null |
||
161 | */ |
||
162 | public function getBody(): ?string |
||
166 | |||
167 | /** |
||
168 | * @param string|null $body |
||
169 | * @return AndroidNotification |
||
170 | */ |
||
171 | public function setBody(?string $body): self |
||
177 | |||
178 | /** |
||
179 | * @return string|null |
||
180 | */ |
||
181 | public function getIcon(): ?string |
||
185 | |||
186 | /** |
||
187 | * @param string|null $icon |
||
188 | * @return AndroidNotification |
||
189 | */ |
||
190 | public function setIcon(?string $icon): self |
||
196 | |||
197 | /** |
||
198 | * @return string|null |
||
199 | */ |
||
200 | public function getColor(): ?string |
||
204 | |||
205 | /** |
||
206 | * @param string|null $color |
||
207 | * @return AndroidNotification |
||
208 | */ |
||
209 | public function setColor(?string $color): self |
||
215 | |||
216 | /** |
||
217 | * @return string|null |
||
218 | */ |
||
219 | public function getSound(): ?string |
||
223 | |||
224 | /** |
||
225 | * @param string|null $sound |
||
226 | * @return AndroidNotification |
||
227 | */ |
||
228 | public function setSound(?string $sound): self |
||
234 | |||
235 | /** |
||
236 | * @return string|null |
||
237 | */ |
||
238 | public function getTag(): ?string |
||
242 | |||
243 | /** |
||
244 | * @param string|null $tag |
||
245 | * @return AndroidNotification |
||
246 | */ |
||
247 | public function setTag(?string $tag): self |
||
253 | |||
254 | /** |
||
255 | * @return string|null |
||
256 | */ |
||
257 | public function getClickAction(): ?string |
||
261 | |||
262 | /** |
||
263 | * @param string|null $clickAction |
||
264 | * @return AndroidNotification |
||
265 | */ |
||
266 | public function setClickAction(?string $clickAction): self |
||
272 | |||
273 | /** |
||
274 | * @return string|null |
||
275 | */ |
||
276 | public function getBodyLocKey(): ?string |
||
280 | |||
281 | /** |
||
282 | * @param string|null $bodyLocKey |
||
283 | * @return AndroidNotification |
||
284 | */ |
||
285 | public function setBodyLocKey(?string $bodyLocKey): self |
||
291 | |||
292 | /** |
||
293 | * @return string[]|null |
||
294 | */ |
||
295 | public function getBodyLocArgs(): ?array |
||
299 | |||
300 | /** |
||
301 | * @param string[]|null $bodyLocArgs |
||
302 | * @return AndroidNotification |
||
303 | */ |
||
304 | public function setBodyLocArgs(?array $bodyLocArgs): self |
||
310 | |||
311 | /** |
||
312 | * @return string|null |
||
313 | */ |
||
314 | public function getTitleLocKey(): ?string |
||
318 | |||
319 | /** |
||
320 | * @param string|null $titleLocKey |
||
321 | * @return AndroidNotification |
||
322 | */ |
||
323 | public function setTitleLocKey(?string $titleLocKey): self |
||
329 | |||
330 | /** |
||
331 | * @return string[]|null |
||
332 | */ |
||
333 | public function getTitleLocArgs(): ?array |
||
337 | |||
338 | /** |
||
339 | * @param string[]|null $titleLocArgs |
||
340 | * @return AndroidNotification |
||
341 | */ |
||
342 | public function setTitleLocArgs(?array $titleLocArgs): self |
||
348 | |||
349 | /** |
||
350 | * @return string|null |
||
351 | */ |
||
352 | public function getChannelId(): ?string |
||
356 | |||
357 | /** |
||
358 | * @param string|null $channelId |
||
359 | * @return AndroidNotification |
||
360 | */ |
||
361 | public function setChannelId(?string $channelId): self |
||
367 | |||
368 | /** |
||
369 | * @return string|null |
||
370 | */ |
||
371 | public function getTicker(): ?string |
||
375 | |||
376 | /** |
||
377 | * @param string|null $ticker |
||
378 | * @return AndroidNotification |
||
379 | */ |
||
380 | public function setTicker(?string $ticker): self |
||
386 | |||
387 | /** |
||
388 | * @return bool|null |
||
389 | */ |
||
390 | public function getSticky(): ?bool |
||
394 | |||
395 | /** |
||
396 | * @param bool|null $sticky |
||
397 | * @return AndroidNotification |
||
398 | */ |
||
399 | public function setSticky(?bool $sticky): self |
||
405 | |||
406 | /** |
||
407 | * @return string|null |
||
408 | */ |
||
409 | public function getEventTime(): ?string |
||
413 | |||
414 | /** |
||
415 | * @param string|null $eventTime |
||
416 | * @return AndroidNotification |
||
417 | */ |
||
418 | public function setEventTime(?string $eventTime): self |
||
424 | |||
425 | /** |
||
426 | * @return bool|null |
||
427 | */ |
||
428 | public function getLocalOnly(): ?bool |
||
432 | |||
433 | /** |
||
434 | * @param bool|null $localOnly |
||
435 | * @return AndroidNotification |
||
436 | */ |
||
437 | public function setLocalOnly(?bool $localOnly): self |
||
443 | |||
444 | /** |
||
445 | * @return NotificationPriority|null |
||
446 | */ |
||
447 | public function getNotificationPriority(): ?NotificationPriority |
||
451 | |||
452 | /** |
||
453 | * @param NotificationPriority|null $notificationPriority |
||
454 | * @return AndroidNotification |
||
455 | */ |
||
456 | public function setNotificationPriority(?NotificationPriority $notificationPriority): self |
||
462 | |||
463 | /** |
||
464 | * @return bool|null |
||
465 | */ |
||
466 | public function getDefaultSound(): ?bool |
||
470 | |||
471 | /** |
||
472 | * @param bool|null $defaultSound |
||
473 | * @return AndroidNotification |
||
474 | */ |
||
475 | public function setDefaultSound(?bool $defaultSound): self |
||
481 | |||
482 | /** |
||
483 | * @return bool|null |
||
484 | */ |
||
485 | public function getDefaultVibrateTimings(): ?bool |
||
489 | |||
490 | /** |
||
491 | * @param bool|null $defaultVibrateTimings |
||
492 | * @return AndroidNotification |
||
493 | */ |
||
494 | public function setDefaultVibrateTimings(?bool $defaultVibrateTimings): self |
||
500 | |||
501 | /** |
||
502 | * @return bool|null |
||
503 | */ |
||
504 | public function getDefaultLightSettings(): ?bool |
||
508 | |||
509 | /** |
||
510 | * @param bool|null $defaultLightSettings |
||
511 | * @return AndroidNotification |
||
512 | */ |
||
513 | public function setDefaultLightSettings(?bool $defaultLightSettings): self |
||
519 | |||
520 | /** |
||
521 | * @return string[]|null |
||
522 | */ |
||
523 | public function getVibrateTimings(): ?array |
||
527 | |||
528 | /** |
||
529 | * @param string[]|null $vibrateTimings |
||
530 | * @return AndroidNotification |
||
531 | */ |
||
532 | public function setVibrateTimings(?array $vibrateTimings): self |
||
538 | |||
539 | /** |
||
540 | * @return Visibility|null |
||
541 | */ |
||
542 | public function getVisibility(): ?Visibility |
||
546 | |||
547 | /** |
||
548 | * @param Visibility|null $visibility |
||
549 | * @return AndroidNotification |
||
550 | */ |
||
551 | public function setVisibility(?Visibility $visibility): self |
||
557 | |||
558 | /** |
||
559 | * @return int|null |
||
560 | */ |
||
561 | public function getNotificationCount(): ?int |
||
565 | |||
566 | /** |
||
567 | * @param int|null $notificationCount |
||
568 | * @return AndroidNotification |
||
569 | */ |
||
570 | public function setNotificationCount(?int $notificationCount): self |
||
576 | |||
577 | /** |
||
578 | * @return LightSettings|null |
||
579 | */ |
||
580 | public function getLightSettings(): ?LightSettings |
||
584 | |||
585 | /** |
||
586 | * @param LightSettings|null $lightSettings |
||
587 | * @return AndroidNotification |
||
588 | */ |
||
589 | public function setLightSettings(?LightSettings $lightSettings): self |
||
595 | |||
596 | /** |
||
597 | * @return string|null |
||
598 | */ |
||
599 | public function getImage(): ?string |
||
603 | |||
604 | /** |
||
605 | * @param string|null $image |
||
606 | * @return AndroidNotification |
||
607 | */ |
||
608 | public function setImage(?string $image): self |
||
614 | |||
615 | /** |
||
616 | * {@inheritdoc} |
||
617 | */ |
||
618 | public function toArray(): array |
||
648 | } |
||
649 |