Complex classes like TimeValue 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 TimeValue, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class TimeValue extends DataValueObject { |
||
16 | |||
17 | /** |
||
18 | * @deprecated since 0.8, use PRECISION_YEAR1G instead |
||
19 | */ |
||
20 | const PRECISION_Ga = self::PRECISION_YEAR1G; |
||
|
|||
21 | |||
22 | /** |
||
23 | * @deprecated since 0.8, use PRECISION_YEAR100M instead |
||
24 | */ |
||
25 | const PRECISION_100Ma = self::PRECISION_YEAR100M; |
||
26 | |||
27 | /** |
||
28 | * @deprecated since 0.8, use PRECISION_YEAR10M instead |
||
29 | */ |
||
30 | const PRECISION_10Ma = self::PRECISION_YEAR10M; |
||
31 | |||
32 | /** |
||
33 | * @deprecated since 0.8, use PRECISION_YEAR1M instead |
||
34 | */ |
||
35 | const PRECISION_Ma = self::PRECISION_YEAR1M; |
||
36 | |||
37 | /** |
||
38 | * @deprecated since 0.8, use PRECISION_YEAR100K instead |
||
39 | */ |
||
40 | const PRECISION_100ka = self::PRECISION_YEAR100K; |
||
41 | |||
42 | /** |
||
43 | * @deprecated since 0.8, use PRECISION_YEAR10K instead |
||
44 | */ |
||
45 | const PRECISION_10ka = self::PRECISION_YEAR10K; |
||
46 | |||
47 | /** |
||
48 | * @deprecated since 0.8, use PRECISION_YEAR1K instead |
||
49 | */ |
||
50 | const PRECISION_ka = self::PRECISION_YEAR1K; |
||
51 | |||
52 | /** |
||
53 | * @deprecated since 0.8, use PRECISION_YEAR100 instead |
||
54 | */ |
||
55 | const PRECISION_100a = self::PRECISION_YEAR100; |
||
56 | |||
57 | /** |
||
58 | * @deprecated since 0.8, use PRECISION_YEAR10 instead |
||
59 | */ |
||
60 | const PRECISION_10a = self::PRECISION_YEAR10; |
||
61 | |||
62 | /** |
||
63 | * @since 0.8 |
||
64 | */ |
||
65 | const PRECISION_YEAR1G = 0; |
||
66 | |||
67 | /** |
||
68 | * @since 0.8 |
||
69 | */ |
||
70 | const PRECISION_YEAR100M = 1; |
||
71 | |||
72 | /** |
||
73 | * @since 0.8 |
||
74 | */ |
||
75 | const PRECISION_YEAR10M = 2; |
||
76 | |||
77 | /** |
||
78 | * @since 0.8 |
||
79 | */ |
||
80 | const PRECISION_YEAR1M = 3; |
||
81 | |||
82 | /** |
||
83 | * @since 0.8 |
||
84 | */ |
||
85 | const PRECISION_YEAR100K = 4; |
||
86 | |||
87 | /** |
||
88 | * @since 0.8 |
||
89 | */ |
||
90 | const PRECISION_YEAR10K = 5; |
||
91 | |||
92 | /** |
||
93 | * @since 0.8 |
||
94 | */ |
||
95 | const PRECISION_YEAR1K = 6; |
||
96 | |||
97 | /** |
||
98 | * @since 0.8 |
||
99 | */ |
||
100 | const PRECISION_YEAR100 = 7; |
||
101 | |||
102 | /** |
||
103 | * @since 0.8 |
||
104 | */ |
||
105 | const PRECISION_YEAR10 = 8; |
||
106 | |||
107 | const PRECISION_YEAR = 9; |
||
108 | const PRECISION_MONTH = 10; |
||
109 | const PRECISION_DAY = 11; |
||
110 | const PRECISION_HOUR = 12; |
||
111 | const PRECISION_MINUTE = 13; |
||
112 | const PRECISION_SECOND = 14; |
||
113 | |||
114 | /** |
||
115 | * @since 0.7.1 |
||
116 | */ |
||
117 | const CALENDAR_GREGORIAN = 'http://www.wikidata.org/entity/Q1985727'; |
||
118 | |||
119 | /** |
||
120 | * @since 0.7.1 |
||
121 | */ |
||
122 | const CALENDAR_JULIAN = 'http://www.wikidata.org/entity/Q1985786'; |
||
123 | |||
124 | /** |
||
125 | * Timestamp describing a point in time. The actual format depends on the calendar model. |
||
126 | * |
||
127 | * Gregorian and Julian dates use the same YMD ordered format, resembling ISO 8601, e.g. |
||
128 | * +2013-01-01T00:00:00Z. In this format the year is always signed and padded with zero |
||
129 | * characters to have between 4 and 16 digits. Month and day can be zero, indicating they are |
||
130 | * unknown. The timezone suffix Z is meaningless and must be ignored. Use getTimezone() instead. |
||
131 | * |
||
132 | * @see $timezone |
||
133 | * @see $calendarModel |
||
134 | * |
||
135 | * @var string |
||
136 | */ |
||
137 | private $timestamp; |
||
138 | |||
139 | /** |
||
140 | * Unit used for the getBefore() and getAfter() values. Use one of the self::PRECISION_... |
||
141 | * constants. |
||
142 | * |
||
143 | * @var int |
||
144 | */ |
||
145 | private $precision; |
||
146 | |||
147 | /** |
||
148 | * If the date is uncertain, how many units after the given time could it be? |
||
149 | * The unit is given by the precision. |
||
150 | * |
||
151 | * @var int Amount |
||
152 | */ |
||
153 | private $after; |
||
154 | |||
155 | /** |
||
156 | * If the date is uncertain, how many units before the given time could it be? |
||
157 | * The unit is given by the precision. |
||
158 | * |
||
159 | * @var int Amount |
||
160 | */ |
||
161 | private $before; |
||
162 | |||
163 | /** |
||
164 | * Time zone information as an offset from UTC in minutes. |
||
165 | * |
||
166 | * @var int Minutes |
||
167 | */ |
||
168 | private $timezone; |
||
169 | |||
170 | /** |
||
171 | * URI identifying the calendar model. The actual timestamp should be in this calendar model, |
||
172 | * but note that there is nothing this class can do to enforce this convention. |
||
173 | * |
||
174 | * @var string URI |
||
175 | */ |
||
176 | private $calendarModel; |
||
177 | |||
178 | /** |
||
179 | * @param string $timestamp Timestamp in a format resembling ISO 8601. |
||
180 | * @param int $timezone Time zone offset from UTC in minutes. |
||
181 | * @param int $before Number of units given by the precision. |
||
182 | * @param int $after Number of units given by the precision. |
||
183 | * @param int $precision One of the self::PRECISION_... constants. |
||
184 | * @param string $calendarModel An URI identifying the calendar model. |
||
185 | * |
||
186 | * @throws IllegalValueException |
||
187 | */ |
||
188 | 75 | public function __construct( $timestamp, $timezone, $before, $after, $precision, $calendarModel ) { |
|
225 | |||
226 | /** |
||
227 | * @param string $timestamp |
||
228 | * |
||
229 | * @throws IllegalValueException |
||
230 | * @return string |
||
231 | */ |
||
232 | 68 | private function normalizeIsoTimestamp( $timestamp ) { |
|
269 | |||
270 | /** |
||
271 | * @see $timestamp |
||
272 | * |
||
273 | * @return string |
||
274 | */ |
||
275 | 19 | public function getTime() { |
|
278 | |||
279 | /** |
||
280 | * @see $calendarModel |
||
281 | * |
||
282 | * @return string URI |
||
283 | */ |
||
284 | 12 | public function getCalendarModel() { |
|
287 | |||
288 | /** |
||
289 | * @see $before |
||
290 | * |
||
291 | * @return int Amount |
||
292 | */ |
||
293 | 12 | public function getBefore() { |
|
296 | |||
297 | /** |
||
298 | * @see $after |
||
299 | * |
||
300 | * @return int Amount |
||
301 | */ |
||
302 | 12 | public function getAfter() { |
|
305 | |||
306 | /** |
||
307 | * @see $precision |
||
308 | * |
||
309 | * @return int one of the self::PRECISION_... constants |
||
310 | */ |
||
311 | 12 | public function getPrecision() { |
|
314 | |||
315 | /** |
||
316 | * @see $timezone |
||
317 | * |
||
318 | * @return int Minutes |
||
319 | */ |
||
320 | 12 | public function getTimezone() { |
|
323 | |||
324 | /** |
||
325 | * @see DataValue::getType |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | 24 | public static function getType() { |
|
332 | |||
333 | /** |
||
334 | * @see DataValue::getSortKey |
||
335 | * |
||
336 | * @return string |
||
337 | */ |
||
338 | public function getSortKey() { |
||
341 | |||
342 | /** |
||
343 | * @see DataValue::getValue |
||
344 | * |
||
345 | * @return self |
||
346 | */ |
||
347 | 24 | public function getValue() { |
|
350 | |||
351 | /** |
||
352 | * @see Serializable::serialize |
||
353 | * |
||
354 | * @return string |
||
355 | */ |
||
356 | 36 | public function serialize() { |
|
359 | |||
360 | /** |
||
361 | * @see Serializable::unserialize |
||
362 | * |
||
363 | * @param string $value |
||
364 | * |
||
365 | * @throws IllegalValueException |
||
366 | */ |
||
367 | 36 | public function unserialize( $value ) { |
|
371 | |||
372 | /** |
||
373 | * @see DataValue::getArrayValue |
||
374 | * |
||
375 | * @return array |
||
376 | */ |
||
377 | 60 | public function getArrayValue() { |
|
387 | |||
388 | /** |
||
389 | * Constructs a new instance from the provided data. Required for @see DataValueDeserializer. |
||
390 | * This is expected to round-trip with @see getArrayValue. |
||
391 | * |
||
392 | * @deprecated since 0.8.5. Static DataValue::newFromArray constructors like this are |
||
393 | * underspecified (not in the DataValue interface), and misleadingly named (should be named |
||
394 | * newFromArrayValue). Instead, use DataValue builder callbacks in @see DataValueDeserializer. |
||
395 | * |
||
396 | * @param mixed $data Warning! Even if this is expected to be a value as returned by |
||
397 | * @see getArrayValue, callers of this specific newFromArray implementation can not guarantee |
||
398 | * this. This is not even guaranteed to be an array! |
||
399 | * |
||
400 | * @throws IllegalValueException if $data is not in the expected format. Subclasses of |
||
401 | * InvalidArgumentException are expected and properly handled by @see DataValueDeserializer. |
||
402 | * @return self |
||
403 | */ |
||
404 | public static function newFromArray( $data ) { |
||
419 | |||
420 | public function __toString() { |
||
423 | |||
424 | } |
||
425 |