Complex classes like PassValidator 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 PassValidator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class PassValidator implements PassValidatorInterface |
||
20 | { |
||
21 | private $errors; |
||
22 | |||
23 | const DESCRIPTION_REQUIRED = 'description is required and cannot be blank'; |
||
24 | const FORMAT_VERSION_REQUIRED = 'formatVersion is required and must be 1'; |
||
25 | const ORGANIZATION_NAME_REQUIRED = 'organizationName is required and cannot be blank'; |
||
26 | const PASS_TYPE_IDENTIFIER_REQUIRED = 'passTypeIdentifier is required and cannot be blank'; |
||
27 | const SERIAL_NUMBER_REQUIRED = 'serialNumber is required and cannot be blank'; |
||
28 | const TEAM_IDENTIFIER_REQUIRED = 'teamIdentifier is required and cannot be blank'; |
||
29 | const ICON_REQUIRED = 'pass must have an icon image'; |
||
30 | const BARCODE_FORMAT_INVALID = 'barcode format is invalid'; |
||
31 | const BARCODE_MESSAGE_INVALID = 'barcode message is invalid; must be a string'; |
||
32 | const LOCATION_LATITUDE_REQUIRED = 'location latitude is required'; |
||
33 | const LOCATION_LONGITUDE_REQUIRED = 'location longitude is required'; |
||
34 | const LOCATION_LATITUDE_INVALID = 'location latitude is invalid; must be numeric'; |
||
35 | const LOCATION_LONGITUDE_INVALID = 'location longitude is invalid; must be numeric'; |
||
36 | const LOCATION_ALTITUDE_INVALID = 'location altitude is invalid; must be numeric'; |
||
37 | const BEACON_PROXIMITY_UUID_REQUIRED = 'beacon proximityUUID is required'; |
||
38 | const BEACON_MAJOR_INVALID = 'beacon major is invalid; must be 16-bit unsigned integer'; |
||
39 | const BEACON_MINOR_INVALID = 'beacon minor is invalid; must be 16-bit unsigned integer'; |
||
40 | const WEB_SERVICE_URL_INVALID = 'webServiceURL is invalid; must start with https (or http for development)'; |
||
41 | const WEB_SERVICE_AUTHENTICATION_TOKEN_REQUIRED = 'authenticationToken required with webServiceURL and cannot be blank'; |
||
42 | const WEB_SERVICE_AUTHENTICATION_TOKEN_INVALID = 'authenticationToken is invalid; must be at least 16 characters'; |
||
43 | const ASSOCIATED_STORE_IDENTIFIER_INVALID = 'associatedStoreIdentifiers is invalid; must be an integer'; |
||
44 | const ASSOCIATED_STORE_IDENTIFIER_REQUIRED = 'appLaunchURL is required when associatedStoreIdentifiers is present'; |
||
45 | const IMAGE_TYPE_INVALID = 'image files must be PNG format'; |
||
46 | const GROUPING_IDENTITY_INVALID = 'the grouping identity may only be used on boarding pass and event ticket types'; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function validate(PassInterface $pass) |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getErrors() |
||
75 | |||
76 | private function validateRequiredFields(PassInterface $pass) |
||
102 | |||
103 | private function validateBeaconKeys(PassInterface $pass) |
||
111 | |||
112 | private function validateBeacon(Beacon $beacon) |
||
130 | |||
131 | private function validateLocationKeys(PassInterface $pass) |
||
139 | |||
140 | private function validateLocation(Location $location) |
||
162 | |||
163 | private function validateBarcodeKeys(PassInterface $pass) |
||
181 | |||
182 | private function validateWebServiceKeys(PassInterface $pass) |
||
200 | |||
201 | private function validateIcon(PassInterface $pass) |
||
211 | |||
212 | private function validateImageType(PassInterface $pass) |
||
221 | |||
222 | private function validateAssociatedStoreIdentifiers(PassInterface $pass) |
||
241 | |||
242 | private function validateGroupingIdentity(PassInterface $pass) |
||
250 | |||
251 | private function isBlankOrNull($text) |
||
255 | |||
256 | private function addError($string) |
||
260 | |||
261 | } |
||
262 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.