Complex classes like DateFormatParser 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 DateFormatParser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class DateFormatParser extends StringValueParser { |
||
18 | |||
19 | const FORMAT_NAME = 'datetime'; |
||
20 | |||
21 | const OPT_DATE_FORMAT = 'dateFormat'; |
||
22 | |||
23 | /** |
||
24 | * Option for unlocalizing non-canonical digits. Must be an array of strings, mapping canonical |
||
25 | * digit characters ("1", "2" and so on, possibly including "." and ",") to localized |
||
26 | * characters. |
||
27 | */ |
||
28 | const OPT_DIGIT_TRANSFORM_TABLE = 'digitTransformTable'; |
||
29 | |||
30 | /** |
||
31 | * Option for localized month names. Should be a two-dimensional array, the first dimension |
||
32 | * mapping the month's numbers 1 to 12 to arrays of localized month names, possibly including |
||
33 | * full month names, genitive names and abbreviations. Can also be a one-dimensional array of |
||
34 | * strings. |
||
35 | */ |
||
36 | const OPT_MONTH_NAMES = 'monthNames'; |
||
37 | |||
38 | public function __construct( ParserOptions $options = null ) { |
||
46 | |||
47 | /** |
||
48 | * @see StringValueParser::stringParse |
||
49 | * |
||
50 | * @param string $value |
||
51 | * |
||
52 | * @throws ParseException |
||
53 | * @return TimeValue |
||
54 | */ |
||
55 | protected function stringParse( $value ) { |
||
96 | |||
97 | /** |
||
98 | * @see Language::sprintfDate |
||
99 | * |
||
100 | * @param string $format A date format, as described in Language::sprintfDate. |
||
101 | * |
||
102 | * @return string Regular expression |
||
103 | */ |
||
104 | private function parseDateFormat( $format ) { |
||
181 | |||
182 | /** |
||
183 | * @return string |
||
184 | */ |
||
185 | private function getMonthNamesPattern() { |
||
196 | |||
197 | /** |
||
198 | * @param string[] $matches |
||
199 | * |
||
200 | * @return int |
||
201 | */ |
||
202 | private function findMonthMatch( $matches ) { |
||
211 | |||
212 | /** |
||
213 | * @param string $number |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | private function parseFormattedNumber( $number ) { |
||
228 | |||
229 | /** |
||
230 | * @return string |
||
231 | */ |
||
232 | private function getNumberCharacters() { |
||
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | */ |
||
246 | private function getDateFormat() { |
||
249 | |||
250 | /** |
||
251 | * @return string[]|null |
||
252 | */ |
||
253 | private function getDigitTransformTable() { |
||
256 | |||
257 | /** |
||
258 | * @return array[] |
||
259 | */ |
||
260 | private function getMonthNames() { |
||
263 | |||
264 | } |
||
265 |