Complex classes like TimeValueFormatter 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 TimeValueFormatter, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class TimeValueFormatter extends DataValueFormatter { |
||
21 | |||
22 | /** |
||
23 | * @since 2.4 |
||
24 | * |
||
25 | * {@inheritDoc} |
||
26 | */ |
||
27 | public function isFormatterFor( DataValue $dataValue ) { |
||
30 | |||
31 | /** |
||
32 | * @since 2.4 |
||
33 | * |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | public function format( $type, $linker = null ) { |
||
57 | |||
58 | /** |
||
59 | * @private |
||
60 | * |
||
61 | * Compute a string representation that largely follows the ISO8601 standard |
||
62 | * of representing dates. Large year numbers may have more than 4 digits, |
||
63 | * which is not strictly conforming to the standard. The date includes year, |
||
64 | * month, and day regardless of the input precision, but will only include |
||
65 | * time when specified. |
||
66 | * |
||
67 | * Conforming to the 2000 version of ISO8601, year 1 BC(E) is represented |
||
68 | * as "0000", year 2 BC(E) as "-0001" and so on. |
||
69 | * |
||
70 | * @since 2.4 |
||
71 | * |
||
72 | * @param DITime $dataItem |
||
|
|||
73 | * @param boolean $mindefault determining whether values below the |
||
74 | * precision of our input should be completed with minimal or maximal |
||
75 | * conceivable values |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | public function getISO8601Date( $mindefault = true ) { |
||
104 | |||
105 | /** |
||
106 | * @private |
||
107 | * |
||
108 | * Use MediaWiki's date and time formatting. It can't handle all inputs |
||
109 | * properly, but has superior i18n support. |
||
110 | * |
||
111 | * @since 2.4 |
||
112 | * |
||
113 | * @param DITime $dataItem |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getMediaWikiDate() { |
||
147 | |||
148 | /** |
||
149 | * @private |
||
150 | * |
||
151 | * @todo Internationalize the CE and BCE strings. |
||
152 | * |
||
153 | * Compute a suitable string to display the given date item. |
||
154 | * |
||
155 | * @note MediaWiki's date functions are not applicable for the range of |
||
156 | * historic dates we support. |
||
157 | * |
||
158 | * @since 2.4 |
||
159 | * |
||
160 | * @param DITime $dataitem |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getCaptionFromDataItem( DITime $dataItem ) { |
||
190 | |||
191 | /** |
||
192 | * @private |
||
193 | * |
||
194 | * Return the time as a string. The time string has the format HH:MM:SS, |
||
195 | * without any timezone information (see class documentation for details |
||
196 | * on current timezone handling). |
||
197 | * The parameter $default optionally specifies the value returned |
||
198 | * if the date is valid but has no explicitly specified time. It can |
||
199 | * also be set to false to detect this situation. |
||
200 | * |
||
201 | * @since 2.4 |
||
202 | * |
||
203 | * @param string $default |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getTimeString( $default = '00:00:00' ) { |
||
219 | |||
220 | /** |
||
221 | * Compute a suitable string to display this date, taking into account the |
||
222 | * output format and the preferrable calendar models for the data. |
||
223 | * |
||
224 | * @note MediaWiki's date functions are not applicable for the range |
||
225 | * of historic dates we support. |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | protected function getPreferredCaption() { |
||
259 | |||
260 | } |
||
261 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.