Complex classes like Pass 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 Pass, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class Pass implements PassInterface |
||
31 | { |
||
32 | /** |
||
33 | * Serial number that uniquely identifies the pass. |
||
34 | * No two passes with the same pass type identifier |
||
35 | * may have the same serial number. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $serialNumber; |
||
40 | |||
41 | /** |
||
42 | * Brief description of the pass, |
||
43 | * used by the iOS accessibility technologies. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $description; |
||
48 | |||
49 | /** |
||
50 | * The name used for the pass. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $passName; |
||
55 | |||
56 | /** |
||
57 | * Version of the file format. |
||
58 | * The value must be 1. |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $formatVersion = 1; |
||
63 | |||
64 | /** |
||
65 | * Pass type |
||
66 | * |
||
67 | * @var string |
||
68 | */ |
||
69 | protected $type; |
||
70 | |||
71 | /** |
||
72 | * Pass structure |
||
73 | * |
||
74 | * @var Structure |
||
75 | */ |
||
76 | protected $structure; |
||
77 | |||
78 | /** |
||
79 | * Pass images |
||
80 | * |
||
81 | * @var ImageInterface[] |
||
82 | */ |
||
83 | protected $images = array(); |
||
84 | |||
85 | /** |
||
86 | * Beacons where the pass is relevant. |
||
87 | * |
||
88 | * @var array |
||
89 | */ |
||
90 | protected $beacons = array(); |
||
91 | |||
92 | /** |
||
93 | * A list of iTunes Store item identifiers (also known as Adam IDs) for the |
||
94 | * associated apps. |
||
95 | * |
||
96 | * Only one item in the list is used—the first item identifier for an app |
||
97 | * compatible with the current device. If the app is not installed, the |
||
98 | * link opens the App Store and shows the app. If the app is already |
||
99 | * installed, the link launches the app. |
||
100 | * |
||
101 | * @var int[] |
||
102 | */ |
||
103 | protected $associatedStoreIdentifiers = array(); |
||
104 | |||
105 | /** |
||
106 | * Locations where the pass is relevant. |
||
107 | * For example, the location of your store. |
||
108 | * |
||
109 | * @var array |
||
110 | */ |
||
111 | protected $locations = array(); |
||
112 | |||
113 | /** |
||
114 | * List of localizations |
||
115 | * |
||
116 | * @var LocalizationInterface[] |
||
117 | */ |
||
118 | protected $localizations = array(); |
||
119 | |||
120 | /** |
||
121 | * Date and time when the pass becomes relevant. |
||
122 | * For example, the start time of a movie. |
||
123 | * |
||
124 | * @var DateTime |
||
125 | */ |
||
126 | protected $relevantDate; |
||
127 | |||
128 | /** |
||
129 | * Maximum distance in meters from a relevant latitude and longitude that |
||
130 | * the pass is relevant. This number is compared to the pass’s default |
||
131 | * distance and the smaller value is used. |
||
132 | * Available in iOS 7.0. |
||
133 | * @var int |
||
134 | */ |
||
135 | protected $maxDistance; |
||
136 | |||
137 | /** |
||
138 | * Barcodes available to be displayed of iOS 9 and later. The system uses |
||
139 | * the first valid barcode in the array. |
||
140 | * @var BarcodeInterface[] |
||
141 | */ |
||
142 | protected $barcodes = array(); |
||
143 | |||
144 | /** |
||
145 | * Barcode to be displayed for iOS 8 and earlier. |
||
146 | * @var BarcodeInterface |
||
147 | */ |
||
148 | protected $barcode; |
||
149 | |||
150 | /** |
||
151 | * Background color of the pass, specified as an CSS-style RGB triple. |
||
152 | * |
||
153 | * @var string rgb(23, 187, 82) |
||
154 | */ |
||
155 | protected $backgroundColor; |
||
156 | |||
157 | /** |
||
158 | * Foreground color of the pass, specified as a CSS-style RGB triple. |
||
159 | * |
||
160 | * @var string rgb(100, 10, 110) |
||
161 | */ |
||
162 | protected $foregroundColor; |
||
163 | |||
164 | /** |
||
165 | * Color of the label text, specified as a CSS-style RGB triple. |
||
166 | * |
||
167 | * @var string rgb(255, 255, 255) |
||
168 | */ |
||
169 | protected $labelColor; |
||
170 | |||
171 | /** |
||
172 | * Text displayed next to the logo on the pass. |
||
173 | * |
||
174 | * @var string |
||
175 | */ |
||
176 | protected $logoText; |
||
177 | |||
178 | /** |
||
179 | * If true, the strip image is displayed without a shine effect. |
||
180 | * |
||
181 | * @var string The default value is false |
||
182 | */ |
||
183 | protected $suppressStripShine; |
||
184 | |||
185 | /** |
||
186 | * The authentication token to use with the web service. |
||
187 | * The token must be 16 characters or longer. |
||
188 | * |
||
189 | * @var string |
||
190 | */ |
||
191 | protected $authenticationToken; |
||
192 | |||
193 | /** |
||
194 | * The URL of a web service that conforms to the API described in Passbook Web Service Reference. |
||
195 | * http://developer.apple.com/library/ios/documentation/PassKit/Reference/PassKit_WebService/WebService.html#//apple_ref/doc/uid/TP40011988 |
||
196 | * |
||
197 | * @var string |
||
198 | */ |
||
199 | protected $webServiceURL; |
||
200 | |||
201 | /** |
||
202 | * Pass type identifier |
||
203 | * |
||
204 | * @var string |
||
205 | */ |
||
206 | protected $passTypeIdentifier; |
||
207 | |||
208 | /** |
||
209 | * Team identifier |
||
210 | * |
||
211 | * @var string |
||
212 | */ |
||
213 | protected $teamIdentifier; |
||
214 | |||
215 | /** |
||
216 | * Organization name |
||
217 | * |
||
218 | * @var string |
||
219 | */ |
||
220 | protected $organizationName; |
||
221 | |||
222 | /** |
||
223 | * Date and time when the pass expires. |
||
224 | * |
||
225 | * @var DateTime |
||
226 | */ |
||
227 | protected $expirationDate; |
||
228 | |||
229 | /** |
||
230 | * Indicates that the pass is void—for example, a one time use coupon that has been redeemed. The default value is |
||
231 | * false. |
||
232 | * |
||
233 | * @var boolean |
||
234 | */ |
||
235 | protected $voided; |
||
236 | |||
237 | /** |
||
238 | * |
||
239 | * A URL to be passed to the associated app when launching it. |
||
240 | * The app receives this URL in the application:didFinishLaunchingWithOptions: and application:handleOpenURL: |
||
241 | * methods of its app delegate. If this key is present, the associatedStoreIdentifiers key must also be present. |
||
242 | * |
||
243 | * @var string |
||
244 | */ |
||
245 | protected $appLaunchURL; |
||
246 | |||
247 | public function __construct($serialNumber, $description, $passName = '') |
||
254 | |||
255 | public function toArray() |
||
324 | |||
325 | /** |
||
326 | * {@inheritdoc} |
||
327 | */ |
||
328 | public function setSerialNumber($serialNumber) |
||
334 | |||
335 | /** |
||
336 | * {@inheritdoc} |
||
337 | */ |
||
338 | public function getSerialNumber() |
||
342 | |||
343 | /** |
||
344 | * {@inheritdoc} |
||
345 | */ |
||
346 | public function setDescription($description) |
||
352 | |||
353 | /** |
||
354 | * {@inheritdoc} |
||
355 | */ |
||
356 | public function getDescription() |
||
360 | |||
361 | /** |
||
362 | * {@inheritdoc} |
||
363 | */ |
||
364 | public function setpassName($passName) |
||
371 | |||
372 | /** |
||
373 | * {@inheritdoc} |
||
374 | */ |
||
375 | public function getPassName() |
||
379 | |||
380 | /** |
||
381 | * {@inheritdoc} |
||
382 | */ |
||
383 | public function getFormatVersion() |
||
387 | |||
388 | /** |
||
389 | * {@inheritdoc} |
||
390 | */ |
||
391 | public function setFormatVersion($formatVersion) |
||
397 | |||
398 | /** |
||
399 | * {@inheritdoc} |
||
400 | */ |
||
401 | public function getType() |
||
405 | |||
406 | /** |
||
407 | * {@inheritdoc} |
||
408 | */ |
||
409 | public function setType($type) |
||
415 | |||
416 | /** |
||
417 | * {@inheritdoc} |
||
418 | */ |
||
419 | public function setStructure(StructureInterface $structure) |
||
425 | |||
426 | /** |
||
427 | * {@inheritdoc} |
||
428 | */ |
||
429 | public function getStructure() |
||
433 | |||
434 | /** |
||
435 | * {@inheritdoc} |
||
436 | */ |
||
437 | public function addImage(ImageInterface $image) |
||
443 | |||
444 | /** |
||
445 | * {@inheritdoc} |
||
446 | */ |
||
447 | public function getImages() |
||
451 | |||
452 | /** |
||
453 | * {@inheritdoc} |
||
454 | */ |
||
455 | public function addLocalization(LocalizationInterface $localization) |
||
461 | |||
462 | /** |
||
463 | * {@inheritdoc} |
||
464 | */ |
||
465 | public function getLocalizations() |
||
469 | |||
470 | /** |
||
471 | * {@inheritdoc} |
||
472 | */ |
||
473 | public function addAssociatedStoreIdentifier($associatedStoreIdentifier) |
||
479 | |||
480 | /** |
||
481 | * {@inheritdoc} |
||
482 | */ |
||
483 | public function getAssociatedStoreIdentifiers() |
||
487 | |||
488 | /** |
||
489 | * {@inheritdoc} |
||
490 | */ |
||
491 | public function addLocation(LocationInterface $location) |
||
497 | |||
498 | /** |
||
499 | * {@inheritdoc} |
||
500 | */ |
||
501 | public function getLocations() |
||
505 | |||
506 | /** |
||
507 | * {@inheritdoc} |
||
508 | */ |
||
509 | public function addBeacon(BeaconInterface $beacon) |
||
515 | |||
516 | /** |
||
517 | * {@inheritdoc} |
||
518 | */ |
||
519 | public function getBeacons() |
||
523 | |||
524 | /** |
||
525 | * {@inheritdoc} |
||
526 | */ |
||
527 | public function setRelevantDate(\DateTime $relevantDate) |
||
533 | |||
534 | /** |
||
535 | * {@inheritdoc} |
||
536 | */ |
||
537 | public function getRelevantDate() |
||
541 | |||
542 | /** |
||
543 | * {@inheritdoc} |
||
544 | */ |
||
545 | public function setMaxDistance($maxDistance) |
||
551 | |||
552 | /** |
||
553 | * {@inheritdoc} |
||
554 | */ |
||
555 | public function getMaxDistance() |
||
559 | |||
560 | /** |
||
561 | * {@inheritdoc} |
||
562 | */ |
||
563 | public function setBarcode(BarcodeInterface $barcode) |
||
570 | |||
571 | /** |
||
572 | * {@inheritdoc} |
||
573 | */ |
||
574 | public function getBarcode() |
||
578 | |||
579 | /** |
||
580 | * {@inheritdoc} |
||
581 | */ |
||
582 | public function addBarcode(BarcodeInterface $barcode) |
||
592 | |||
593 | /** |
||
594 | * {@inheritdoc} |
||
595 | */ |
||
596 | public function getBarcodes() |
||
600 | |||
601 | /** |
||
602 | * {@inheritdoc} |
||
603 | */ |
||
604 | public function setBackgroundColor($backgroundColor) |
||
610 | |||
611 | /** |
||
612 | * {@inheritdoc} |
||
613 | */ |
||
614 | public function getBackgroundColor() |
||
618 | |||
619 | /** |
||
620 | * {@inheritdoc} |
||
621 | */ |
||
622 | public function setForegroundColor($foregroundColor) |
||
628 | |||
629 | /** |
||
630 | * {@inheritdoc} |
||
631 | */ |
||
632 | public function getForegroundColor() |
||
636 | |||
637 | /** |
||
638 | * {@inheritdoc} |
||
639 | */ |
||
640 | public function setLabelColor($labelColor) |
||
646 | |||
647 | /** |
||
648 | * {@inheritdoc} |
||
649 | */ |
||
650 | public function getLabelColor() |
||
654 | |||
655 | /** |
||
656 | * {@inheritdoc} |
||
657 | */ |
||
658 | public function setLogoText($logoText) |
||
664 | |||
665 | /** |
||
666 | * {@inheritdoc} |
||
667 | */ |
||
668 | public function getLogoText() |
||
672 | |||
673 | /** |
||
674 | * {@inheritdoc} |
||
675 | */ |
||
676 | public function setSuppressStripShine($suppressStripShine) |
||
682 | |||
683 | /** |
||
684 | * {@inheritdoc} |
||
685 | */ |
||
686 | public function getSuppressStripShine() |
||
690 | |||
691 | /** |
||
692 | * {@inheritdoc} |
||
693 | */ |
||
694 | public function setAuthenticationToken($authenticationToken) |
||
700 | |||
701 | /** |
||
702 | * {@inheritdoc} |
||
703 | */ |
||
704 | public function getAuthenticationToken() |
||
708 | |||
709 | /** |
||
710 | * {@inheritdoc} |
||
711 | */ |
||
712 | public function setWebServiceURL($webServiceURL) |
||
718 | |||
719 | /** |
||
720 | * {@inheritdoc} |
||
721 | */ |
||
722 | public function getWebServiceURL() |
||
726 | |||
727 | /** |
||
728 | * {@inheritdoc} |
||
729 | */ |
||
730 | public function setPassTypeIdentifier($passTypeIdentifier) |
||
736 | |||
737 | /** |
||
738 | * {@inheritdoc} |
||
739 | */ |
||
740 | public function getPassTypeIdentifier() |
||
744 | |||
745 | /** |
||
746 | * {@inheritdoc} |
||
747 | */ |
||
748 | public function setTeamIdentifier($teamIdentifier) |
||
754 | |||
755 | /** |
||
756 | * {@inheritdoc} |
||
757 | */ |
||
758 | public function getTeamIdentifier() |
||
762 | |||
763 | /** |
||
764 | * {@inheritdoc} |
||
765 | */ |
||
766 | public function setOrganizationName($organizationName) |
||
772 | |||
773 | /** |
||
774 | * {@inheritdoc} |
||
775 | */ |
||
776 | public function getOrganizationName() |
||
780 | |||
781 | /** |
||
782 | * {@inheritdoc} |
||
783 | */ |
||
784 | public function setExpirationDate(\DateTime $expirationDate) |
||
790 | |||
791 | /** |
||
792 | * {@inheritdoc} |
||
793 | */ |
||
794 | public function getExpirationDate() |
||
798 | |||
799 | /** |
||
800 | * {@inheritdoc} |
||
801 | */ |
||
802 | public function setVoided($voided) |
||
808 | |||
809 | /** |
||
810 | * {@inheritdoc} |
||
811 | */ |
||
812 | public function getVoided() |
||
816 | |||
817 | /** |
||
818 | * {@inheritdoc} |
||
819 | */ |
||
820 | public function setAppLaunchURL($appLaunchURL) |
||
826 | |||
827 | /** |
||
828 | * {@inheritdoc} |
||
829 | */ |
||
830 | public function getAppLaunchURL() |
||
834 | } |
||
835 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.