Complex classes like IsoTimestampParser 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 IsoTimestampParser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class IsoTimestampParser extends StringValueParser { |
||
26 | |||
27 | const FORMAT_NAME = 'iso-timestamp'; |
||
28 | |||
29 | /** |
||
30 | * Option to override the precision auto-detection and set a specific precision. Should be an |
||
31 | * integer or string containing one of the TimeValue::PRECISION_... constants. |
||
32 | */ |
||
33 | const OPT_PRECISION = 'precision'; |
||
34 | |||
35 | /** |
||
36 | * Option to override the calendar model auto-detection and set a specific calendar model URI. |
||
37 | * Should be one of the TimeValue::CALENDAR_... constants. |
||
38 | */ |
||
39 | const OPT_CALENDAR = 'calendar'; |
||
40 | |||
41 | /** |
||
42 | * @deprecated since 0.7.1, use TimeValue::CALENDAR_GREGORIAN instead |
||
43 | */ |
||
44 | const CALENDAR_GREGORIAN = TimeValue::CALENDAR_GREGORIAN; |
||
45 | |||
46 | /** |
||
47 | * @deprecated since 0.7.1, use TimeValue::CALENDAR_JULIAN instead |
||
48 | */ |
||
49 | const CALENDAR_JULIAN = TimeValue::CALENDAR_JULIAN; |
||
50 | |||
51 | /** |
||
52 | * @var CalendarModelParser |
||
53 | */ |
||
54 | private $calendarModelParser; |
||
55 | |||
56 | /** |
||
57 | * @param CalendarModelParser|null $calendarModelParser |
||
58 | * @param ParserOptions|null $options |
||
59 | */ |
||
60 | 40 | public function __construct( |
|
71 | |||
72 | /** |
||
73 | * @param string $value |
||
74 | * |
||
75 | * @throws ParseException |
||
76 | * @return TimeValue |
||
77 | */ |
||
78 | 86 | protected function stringParse( $value ) { |
|
96 | |||
97 | /** |
||
98 | * @param string $value |
||
99 | * |
||
100 | * @throws ParseException |
||
101 | * @return string[] Array with index 0 => sign, 1 => year, 2 => month, 3 => day, 4 => hour, |
||
102 | * 5 => minute, 6 => second and 7 => calendar model. |
||
103 | */ |
||
104 | 86 | private function splitTimeString( $value ) { |
|
151 | |||
152 | /** |
||
153 | * @param string[] $timeParts Array with index 0 => sign, 1 => year, 2 => month, etc. |
||
154 | * |
||
155 | * @throws ParseException |
||
156 | * @return int One of the TimeValue::PRECISION_... constants. |
||
157 | */ |
||
158 | 66 | private function getPrecision( array $timeParts ) { |
|
194 | |||
195 | /** |
||
196 | * @param string $unsignedYear |
||
197 | * |
||
198 | * @return int One of the TimeValue::PRECISION_... constants. |
||
199 | */ |
||
200 | 17 | private function getPrecisionFromYear( $unsignedYear ) { |
|
214 | |||
215 | /** |
||
216 | * Determines the calendar model. The calendar model is determined as follows: |
||
217 | * |
||
218 | * - if $timeParts[7] is set, use $this->calendarModelParser to parse it into a URI. |
||
219 | * - otherwise, if $this->getOption( self::OPT_CALENDAR ) is not null, use |
||
220 | * $this->calendarModelParser to parse it into a URI. |
||
221 | * - otherwise, use self::CALENDAR_JULIAN for dates before 1583, and self::CALENDAR_GREGORIAN |
||
222 | * for later dates. |
||
223 | * |
||
224 | * @note Keep this in sync with HtmlTimeFormatter::getDefaultCalendar(). |
||
225 | * |
||
226 | * @param string[] $timeParts as returned by splitTimeString() |
||
227 | * |
||
228 | * @return string URI |
||
229 | */ |
||
230 | 64 | private function getCalendarModel( array $timeParts ) { |
|
249 | |||
250 | } |
||
251 |
This class constant 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 constant will be removed from the class and what other constant to use instead.