Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
35 | class Datium |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Store DateTime object |
||
40 | */ |
||
41 | protected $date_time; |
||
42 | |||
43 | protected static $static_date_time; |
||
44 | |||
45 | /** |
||
46 | * Store config file statements |
||
47 | * |
||
48 | * @param array |
||
49 | */ |
||
50 | protected $config; |
||
51 | |||
52 | protected $date_interval_expression; |
||
53 | |||
54 | protected static $date_start; |
||
55 | |||
56 | protected static $date_end; |
||
57 | |||
58 | protected $translate_from; |
||
59 | |||
60 | protected $translate_to; |
||
61 | |||
62 | protected $toConfig; |
||
63 | |||
64 | protected $fromConfig; |
||
65 | |||
66 | /** |
||
67 | * Return store day number |
||
68 | * |
||
69 | * @param integer |
||
70 | */ |
||
71 | protected $day_of; |
||
72 | |||
73 | protected $leap; |
||
74 | |||
75 | protected $events; |
||
76 | |||
77 | protected $translate; |
||
78 | |||
79 | protected $gregorian_DayofWeek; |
||
80 | |||
81 | protected $convert_calendar; |
||
82 | |||
83 | protected $calendar_type; |
||
84 | |||
85 | protected static $array_date; |
||
86 | |||
87 | protected static $call_type; |
||
88 | |||
89 | protected $translate_from_file; |
||
90 | |||
91 | protected $translate_to_file; |
||
92 | |||
93 | protected $language; |
||
94 | |||
95 | /** |
||
96 | * Timeago |
||
97 | * |
||
98 | * @param integer |
||
99 | */ |
||
100 | protected $ago; |
||
101 | |||
102 | /** |
||
103 | * Datium class constructure |
||
104 | */ |
||
105 | public function __construct() |
||
158 | |||
159 | /** |
||
160 | * Return all datetime parts as an object |
||
161 | * |
||
162 | * @return object |
||
163 | */ |
||
164 | public function all() |
||
184 | |||
185 | /** |
||
186 | * Get current datetime |
||
187 | * |
||
188 | * @since Aug 17 2015 |
||
189 | * @return object |
||
190 | */ |
||
191 | public static function now() |
||
199 | |||
200 | /** |
||
201 | * Create new date time |
||
202 | * |
||
203 | * @param integer $year Year number |
||
204 | * @param integer $month month number |
||
205 | * @param integer $day day number |
||
206 | * @param integer $hour hour number |
||
207 | * @param integer $minute minute number |
||
208 | * @param integer $second second number |
||
209 | * |
||
210 | * @return object |
||
211 | */ |
||
212 | public static function create( |
||
245 | |||
246 | /** |
||
247 | * Select The range between two date object |
||
248 | * |
||
249 | * @param object $date_start Start of the DateTime |
||
250 | * @param object $date_end End of the DateTime |
||
251 | * |
||
252 | * @return object |
||
253 | */ |
||
254 | public static function between($date_start, $date_end) |
||
266 | |||
267 | /** |
||
268 | * Convert from current calendar, what type is current calendar? |
||
269 | * |
||
270 | * @param object $calendar Assigned calendar to start from |
||
271 | * |
||
272 | * @return $object |
||
|
|||
273 | */ |
||
274 | View Code Duplication | public function from($calendar) |
|
292 | |||
293 | /** |
||
294 | * Convert date to current Date |
||
295 | * |
||
296 | * @param object $calendar Assigned calendar to when calendar should start. |
||
297 | * |
||
298 | * @return object |
||
299 | */ |
||
300 | View Code Duplication | public function to($calendar) |
|
317 | |||
318 | /** |
||
319 | * Difference between two time |
||
320 | * |
||
321 | * @param DateTime $start Start of the date |
||
322 | * @param DateTime $end End of the date |
||
323 | * |
||
324 | * @return object |
||
325 | */ |
||
326 | public static function diff($start, $end) |
||
332 | |||
333 | /** |
||
334 | * Add new date value to current date |
||
335 | * |
||
336 | * @param string $value How much date should be added to current date |
||
337 | * |
||
338 | * @return object |
||
339 | */ |
||
340 | View Code Duplication | public function add($value) |
|
376 | |||
377 | /** |
||
378 | * Sub date from current date |
||
379 | * |
||
380 | * @param string $value How much date should increase from current date |
||
381 | * |
||
382 | * @return obejct |
||
383 | */ |
||
384 | View Code Duplication | public function sub($value) |
|
420 | |||
421 | /** |
||
422 | * Check if current year is leap or not |
||
423 | * |
||
424 | * @param string $type Name of the calendar to caculate leap year |
||
425 | * |
||
426 | * @return boolean |
||
427 | */ |
||
428 | public function leap() |
||
436 | |||
437 | /** |
||
438 | * Calculate how many time ago datetime happens |
||
439 | * |
||
440 | * @return string |
||
441 | */ |
||
442 | public function ago() |
||
450 | |||
451 | /** |
||
452 | * Caculate day of year or week |
||
453 | * |
||
454 | * @since Aug, 22 2015 |
||
455 | * |
||
456 | * @return integer |
||
457 | */ |
||
458 | public function dayOf() |
||
466 | |||
467 | // public function events() |
||
468 | // { |
||
469 | // |
||
470 | // if (Datium::$call_type == 'between' ) { |
||
471 | // |
||
472 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
473 | // |
||
474 | // } else { |
||
475 | // |
||
476 | // $this->events = new Events($this->date_time); |
||
477 | // |
||
478 | // } |
||
479 | // |
||
480 | // return $this->events; |
||
481 | // |
||
482 | // } |
||
483 | |||
484 | /** |
||
485 | * Return Datetime as a original object |
||
486 | * |
||
487 | * @since Oct 22, 2015 |
||
488 | * |
||
489 | * @return object |
||
490 | */ |
||
491 | public function object() |
||
497 | |||
498 | /** |
||
499 | * Translate current date string to selected language |
||
500 | * |
||
501 | * @param string $language language short name fa, en, ar ... |
||
502 | * |
||
503 | * @return object |
||
504 | */ |
||
505 | public function lang($language = 'fa') |
||
519 | |||
520 | /** |
||
521 | * Return object as timestamp |
||
522 | * |
||
523 | * @return timestamp |
||
524 | */ |
||
525 | public function timestamp() |
||
531 | |||
532 | /** |
||
533 | * Return fainal result |
||
534 | * |
||
535 | * @param string $format Date format |
||
536 | * |
||
537 | * @since Aug 17 2015 |
||
538 | * |
||
539 | * @return string |
||
540 | */ |
||
541 | public function get($format = 'Y-m-d H:i:s') |
||
612 | } |
||
613 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.