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 |
||
| 33 | class Datium |
||
| 34 | { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Store DateTime object |
||
| 38 | */ |
||
| 39 | protected $date_time; |
||
| 40 | |||
| 41 | protected static $static_date_time; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Store config file statements |
||
| 45 | * |
||
| 46 | * @param array |
||
| 47 | */ |
||
| 48 | protected $config; |
||
| 49 | |||
| 50 | protected $date_interval_expression; |
||
| 51 | |||
| 52 | protected static $date_start; |
||
| 53 | |||
| 54 | protected static $date_end; |
||
| 55 | |||
| 56 | protected $translate_from; |
||
| 57 | |||
| 58 | protected $translate_to; |
||
| 59 | |||
| 60 | protected $toConfig; |
||
| 61 | |||
| 62 | protected $fromConfig; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Return store day number |
||
| 66 | * |
||
| 67 | * @param integer |
||
| 68 | */ |
||
| 69 | protected $day_of; |
||
| 70 | |||
| 71 | protected $leap; |
||
| 72 | |||
| 73 | protected $events; |
||
| 74 | |||
| 75 | protected $translate; |
||
| 76 | |||
| 77 | protected $gregorian_DayofWeek; |
||
| 78 | |||
| 79 | protected $convert_calendar; |
||
| 80 | |||
| 81 | protected $calendar_type; |
||
| 82 | |||
| 83 | protected static $array_date; |
||
| 84 | |||
| 85 | protected static $call_type; |
||
| 86 | |||
| 87 | protected $translate_from_file; |
||
| 88 | |||
| 89 | protected $translate_to_file; |
||
| 90 | |||
| 91 | protected $language; |
||
| 92 | |||
| 93 | protected static $timestamp; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Timeago |
||
| 97 | * |
||
| 98 | * @param integer |
||
| 99 | */ |
||
| 100 | protected $ago; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Datium class constructure |
||
| 104 | */ |
||
| 105 | public function __construct() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Return all datetime parts as an object |
||
| 171 | * |
||
| 172 | * @return object |
||
| 173 | */ |
||
| 174 | public function all() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Get current datetime |
||
| 197 | * |
||
| 198 | * @since Aug 17 2015 |
||
| 199 | * @return object |
||
| 200 | */ |
||
| 201 | public static function now() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Create new date time |
||
| 212 | * |
||
| 213 | * @param integer $year Year number |
||
| 214 | * @param integer $month month number |
||
| 215 | * @param integer $day day number |
||
| 216 | * @param integer $hour hour number |
||
| 217 | * @param integer $minute minute number |
||
| 218 | * @param integer $second second number |
||
| 219 | * |
||
| 220 | * @return object |
||
| 221 | */ |
||
| 222 | public static function create( |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Accecpt Timestamp as Datium initializion |
||
| 258 | * |
||
| 259 | * @param timestamp $timestamp Input timestamp value |
||
| 260 | * @return object |
||
| 261 | */ |
||
| 262 | public static function createTimestamp( $timestamp ) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Select The range between two date object |
||
| 285 | * |
||
| 286 | * @param object $date_start Start of the DateTime |
||
| 287 | * @param object $date_end End of the DateTime |
||
| 288 | * |
||
| 289 | * @return object |
||
| 290 | */ |
||
| 291 | public static function between($date_start, $date_end) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Convert from current calendar, what type is current calendar? |
||
| 306 | * |
||
| 307 | * @param object $calendar Assigned calendar to start from |
||
| 308 | * |
||
| 309 | * @return $object |
||
|
|
|||
| 310 | */ |
||
| 311 | View Code Duplication | public function from($calendar) |
|
| 329 | |||
| 330 | /** |
||
| 331 | * Convert date to current Date |
||
| 332 | * |
||
| 333 | * @param object $calendar Assigned calendar to when calendar should start. |
||
| 334 | * |
||
| 335 | * @return object |
||
| 336 | */ |
||
| 337 | View Code Duplication | public function to($calendar) |
|
| 354 | |||
| 355 | /** |
||
| 356 | * Difference between two time |
||
| 357 | * |
||
| 358 | * @param DateTime $start Start of the date |
||
| 359 | * @param DateTime $end End of the date |
||
| 360 | * |
||
| 361 | * @return object |
||
| 362 | */ |
||
| 363 | public static function diff($start, $end) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Add new date value to current date |
||
| 386 | * |
||
| 387 | * @param string $value How much date should be added to current date |
||
| 388 | * |
||
| 389 | * @return object |
||
| 390 | */ |
||
| 391 | View Code Duplication | public function add($value) |
|
| 425 | |||
| 426 | /** |
||
| 427 | * Sub date from current date |
||
| 428 | * |
||
| 429 | * @param string $value How much date should increase from current date |
||
| 430 | * |
||
| 431 | * @return obejct |
||
| 432 | */ |
||
| 433 | View Code Duplication | public function sub($value) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Check if current year is leap or not |
||
| 470 | * |
||
| 471 | * @param string $type Name of the calendar to caculate leap year |
||
| 472 | * |
||
| 473 | * @return boolean |
||
| 474 | */ |
||
| 475 | public function leap() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Calculate how many time ago datetime happens |
||
| 486 | * |
||
| 487 | * @return string |
||
| 488 | */ |
||
| 489 | public function ago() |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Caculate day of year or week |
||
| 500 | * |
||
| 501 | * @since Aug, 22 2015 |
||
| 502 | * |
||
| 503 | * @return integer |
||
| 504 | */ |
||
| 505 | public function dayOf() |
||
| 513 | |||
| 514 | // public function events() |
||
| 515 | // { |
||
| 516 | // |
||
| 517 | // if (Datium::$call_type == 'between' ) { |
||
| 518 | // |
||
| 519 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
| 520 | // |
||
| 521 | // } else { |
||
| 522 | // |
||
| 523 | // $this->events = new Events($this->date_time); |
||
| 524 | // |
||
| 525 | // } |
||
| 526 | // |
||
| 527 | // return $this->events; |
||
| 528 | // |
||
| 529 | // } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Return Datetime as a original object |
||
| 533 | * |
||
| 534 | * @since Oct 22, 2015 |
||
| 535 | * |
||
| 536 | * @return object |
||
| 537 | */ |
||
| 538 | public function object() |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Translate current date string to selected language |
||
| 547 | * |
||
| 548 | * @param string $language language short name fa, en, ar ... |
||
| 549 | * |
||
| 550 | * @return object |
||
| 551 | */ |
||
| 552 | public function lang($language = 'fa') |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Return object as timestamp |
||
| 569 | * |
||
| 570 | * @return timestamp |
||
| 571 | */ |
||
| 572 | public function timestamp() |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Return fainal result |
||
| 581 | * |
||
| 582 | * @param string $format Date format |
||
| 583 | * |
||
| 584 | * @since Aug 17 2015 |
||
| 585 | * |
||
| 586 | * @return string |
||
| 587 | */ |
||
| 588 | public function get($format = 'Y-m-d H:i:s') |
||
| 659 | } |
||
| 660 |
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.