Complex classes like MwTimeIsoFormatter 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 MwTimeIsoFormatter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class MwTimeIsoFormatter extends ValueFormatterBase { |
||
21 | |||
22 | /** |
||
23 | * @var Language |
||
24 | */ |
||
25 | private $language; |
||
26 | |||
27 | /** |
||
28 | * @param FormatterOptions|null $options |
||
29 | */ |
||
30 | public function __construct( FormatterOptions $options = null ) { |
||
36 | |||
37 | /** |
||
38 | * @see ValueFormatter::format |
||
39 | * |
||
40 | * @param TimeValue $value |
||
41 | * |
||
42 | * @throws InvalidArgumentException |
||
43 | * @return string Text |
||
44 | */ |
||
45 | public function format( $value ) { |
||
52 | |||
53 | /** |
||
54 | * @param TimeValue $timeValue |
||
55 | * |
||
56 | * @return string Text |
||
57 | */ |
||
58 | private function formatTimeValue( TimeValue $timeValue ) { |
||
67 | |||
68 | /** |
||
69 | * @param string $isoTimestamp |
||
70 | * @param int $precision |
||
71 | * |
||
72 | * @throws InvalidArgumentException |
||
73 | * @return string Formatted date |
||
74 | */ |
||
75 | private function getLocalizedDate( $isoTimestamp, $precision ) { |
||
99 | |||
100 | /** |
||
101 | * @param int $precision |
||
102 | * |
||
103 | * @throws InvalidArgumentException |
||
104 | * @return string Date format string to be used by Language::sprintfDate |
||
105 | */ |
||
106 | private function getDateFormat( $precision ) { |
||
124 | |||
125 | /** |
||
126 | * @see Language::sprintfDate |
||
127 | * |
||
128 | * @param string $dateFormat |
||
129 | * |
||
130 | * @return string A date format for the day that roundtrips the Wikibase TimeParsers. |
||
131 | */ |
||
132 | private function getDayFormat( $dateFormat ) { |
||
139 | |||
140 | /** |
||
141 | * @see Language::sprintfDate |
||
142 | * |
||
143 | * @param string $dateFormat |
||
144 | * |
||
145 | * @return string A date format for the month that roundtrips the Wikibase TimeParsers. |
||
146 | */ |
||
147 | private function getMonthFormat( $dateFormat ) { |
||
154 | |||
155 | /** |
||
156 | * @param string $isoTimestamp |
||
157 | * @param int $precision |
||
158 | * |
||
159 | * @throws InvalidArgumentException |
||
160 | * @return string MediaWiki time stamp in the format YYYYMMDDHHMMSS |
||
161 | */ |
||
162 | private function getMwTimestamp( $isoTimestamp, $precision ) { |
||
173 | |||
174 | /** |
||
175 | * @param string $isoTimestamp |
||
176 | * @param int $precision |
||
177 | * |
||
178 | * @throws InvalidArgumentException |
||
179 | * @return string[] Year, month, day, hour, minute, second |
||
180 | */ |
||
181 | private function splitIsoTimestamp( $isoTimestamp, $precision ) { |
||
201 | |||
202 | /** |
||
203 | * @param string $isoTimestamp |
||
204 | * @param int $precision |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | private function getLocalizedYear( $isoTimestamp, $precision ) { |
||
300 | |||
301 | /** |
||
302 | * @param string $number |
||
303 | * @param string $function |
||
304 | * @param float $shift |
||
305 | * @param float $unshift |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | private function shiftNumber( $number, $function, $shift, $unshift ) { |
||
327 | |||
328 | } |
||
329 |