Complex classes like date_Core 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 date_Core, and based on these observations, apply Extract Interface, too.
1 | <?php defined('SYSPATH') or die('No direct access allowed.'); |
||
12 | class date_Core |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Converts a UNIX timestamp to DOS format. |
||
17 | * |
||
18 | * @param integer UNIX timestamp |
||
19 | * @return integer |
||
20 | */ |
||
21 | public static function unix2dos($timestamp = false) |
||
37 | |||
38 | /** |
||
39 | * Converts a DOS timestamp to UNIX format. |
||
40 | * |
||
41 | * @param integer DOS timestamp |
||
42 | * @return integer |
||
43 | */ |
||
44 | public static function dos2unix($timestamp = false) |
||
55 | |||
56 | /** |
||
57 | * Returns the offset (in seconds) between two time zones. |
||
58 | * @see http://php.net/timezones |
||
59 | * |
||
60 | * @param string timezone that to find the offset of |
||
61 | * @param string|boolean timezone used as the baseline |
||
62 | * @return integer |
||
|
|||
63 | */ |
||
64 | public static function offset($remote, $local = true) |
||
90 | |||
91 | /** |
||
92 | * Number of seconds in a minute, incrementing by a step. |
||
93 | * |
||
94 | * @param integer amount to increment each step by, 1 to 30 |
||
95 | * @param integer start value |
||
96 | * @param integer end value |
||
97 | * @return array A mirrored (foo => foo) array from 1-60. |
||
98 | */ |
||
99 | public static function seconds($step = 1, $start = 0, $end = 60) |
||
112 | |||
113 | /** |
||
114 | * Number of minutes in an hour, incrementing by a step. |
||
115 | * |
||
116 | * @param integer amount to increment each step by, 1 to 30 |
||
117 | * @return array A mirrored (foo => foo) array from 1-60. |
||
118 | */ |
||
119 | public static function minutes($step = 5) |
||
127 | |||
128 | /** |
||
129 | * Number of hours in a day. |
||
130 | * |
||
131 | * @param integer amount to increment each step by |
||
132 | * @param boolean use 24-hour time |
||
133 | * @param integer the hour to start at |
||
134 | * @return array A mirrored (foo => foo) array from start-12 or start-23. |
||
135 | */ |
||
136 | public static function hours($step = 1, $long = false, $start = null) |
||
159 | |||
160 | /** |
||
161 | * Returns AM or PM, based on a given hour. |
||
162 | * |
||
163 | * @param integer number of the hour |
||
164 | * @return string |
||
165 | */ |
||
166 | public static function ampm($hour) |
||
173 | |||
174 | /** |
||
175 | * Adjusts a non-24-hour number into a 24-hour number. |
||
176 | * |
||
177 | * @param integer hour to adjust |
||
178 | * @param string AM or PM |
||
179 | * @return string |
||
180 | */ |
||
181 | public static function adjust($hour, $ampm) |
||
201 | |||
202 | /** |
||
203 | * Number of days in month. |
||
204 | * |
||
205 | * @param integer number of month |
||
206 | * @param integer number of year to check month, defaults to the current year |
||
207 | * @return array A mirrored (foo => foo) array of the days. |
||
208 | */ |
||
209 | public static function days($month, $year = false) |
||
234 | |||
235 | /** |
||
236 | * Number of months in a year |
||
237 | * |
||
238 | * @return array A mirrored (foo => foo) array from 1-12. |
||
239 | */ |
||
240 | public static function months() |
||
244 | |||
245 | /** |
||
246 | * Returns an array of years between a starting and ending year. |
||
247 | * Uses the current year +/- 5 as the max/min. |
||
248 | * |
||
249 | * @param integer starting year |
||
250 | * @param integer ending year |
||
251 | * @return array |
||
252 | */ |
||
253 | public static function years($start = false, $end = false) |
||
270 | |||
271 | /** |
||
272 | * Returns time difference between two timestamps, in human readable format. |
||
273 | * |
||
274 | * @param integer timestamp |
||
275 | * @param integer timestamp, defaults to the current time |
||
276 | * @param string formatting string |
||
277 | * @return string|array |
||
278 | */ |
||
279 | public static function timespan($time1, $time2 = null, $output = 'years,months,weeks,days,hours,minutes,seconds') |
||
351 | |||
352 | /** |
||
353 | * Returns time difference between two timestamps, in the format: |
||
354 | * N year, N months, N weeks, N days, N hours, N minutes, and N seconds ago |
||
355 | * |
||
356 | * @param integer timestamp |
||
357 | * @param integer timestamp, defaults to the current time |
||
358 | * @param string formatting string |
||
359 | * @return string |
||
360 | */ |
||
361 | public static function timespan_string($time1, $time2 = null, $output = 'years,months,weeks,days,hours,minutes,seconds') |
||
393 | } // End date |
||
394 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.