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 | * SimpleDiff |
||
| 97 | * |
||
| 98 | * @param integer |
||
| 99 | */ |
||
| 100 | protected $simpleDiff; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Datium class constructure |
||
| 104 | */ |
||
| 105 | public function __construct() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Return all datetime parts as an object |
||
| 167 | * |
||
| 168 | * @return object |
||
| 169 | */ |
||
| 170 | public function all() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Get current datetime |
||
| 193 | * |
||
| 194 | * @since Aug 17 2015 |
||
| 195 | * @return object |
||
| 196 | */ |
||
| 197 | public static function now() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Set config |
||
| 208 | * |
||
| 209 | * @since June 28 2016 |
||
| 210 | * |
||
| 211 | * @param array $config |
||
| 212 | * |
||
| 213 | * @return $this |
||
| 214 | */ |
||
| 215 | public function setConfig($config = []) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Create new date time |
||
| 226 | * |
||
| 227 | * @param integer $year Year number |
||
| 228 | * @param integer $month month number |
||
| 229 | * @param integer $day day number |
||
| 230 | * @param integer $hour hour number |
||
| 231 | * @param integer $minute minute number |
||
| 232 | * @param integer $second second number |
||
| 233 | * |
||
| 234 | * @return object |
||
| 235 | */ |
||
| 236 | public static function create( |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Accept Timestamp as Datium initializion |
||
| 271 | * |
||
| 272 | * @param timestamp $timestamp Input timestamp value |
||
| 273 | * |
||
| 274 | * @return object |
||
| 275 | */ |
||
| 276 | public static function createTimestamp($timestamp) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Select The range between two date object |
||
| 298 | * |
||
| 299 | * @param object $date_start Start of the DateTime |
||
| 300 | * @param object $date_end End of the DateTime |
||
| 301 | * |
||
| 302 | * @return object |
||
| 303 | */ |
||
| 304 | public static function between($date_start, $date_end) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Convert from current calendar, what type is current calendar? |
||
| 319 | * |
||
| 320 | * @param object $calendar Assigned calendar to start from |
||
| 321 | * |
||
| 322 | * @return $object |
||
|
|
|||
| 323 | */ |
||
| 324 | View Code Duplication | public function from($calendar) |
|
| 342 | |||
| 343 | /** |
||
| 344 | * Convert date to current Date |
||
| 345 | * |
||
| 346 | * @param object $calendar Assigned calendar to when calendar should start. |
||
| 347 | * |
||
| 348 | * @return object |
||
| 349 | */ |
||
| 350 | View Code Duplication | public function to($calendar) |
|
| 367 | |||
| 368 | /** |
||
| 369 | * Difference between two time |
||
| 370 | * |
||
| 371 | * @param DateTime $start Start of the date |
||
| 372 | * @param DateTime $end End of the date |
||
| 373 | * |
||
| 374 | * @return object |
||
| 375 | */ |
||
| 376 | public static function diff($start, $end) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Add new date value to current date |
||
| 401 | * |
||
| 402 | * @param string $value How much date should be added to current date |
||
| 403 | * |
||
| 404 | * @return object |
||
| 405 | */ |
||
| 406 | View Code Duplication | public function add($value) |
|
| 442 | |||
| 443 | /** |
||
| 444 | * Sub date from current date |
||
| 445 | * |
||
| 446 | * @param string $value How much date should increase from current date |
||
| 447 | * |
||
| 448 | * @return obejct |
||
| 449 | */ |
||
| 450 | View Code Duplication | public function sub($value) |
|
| 486 | |||
| 487 | /** |
||
| 488 | * Check if current year is leap or not |
||
| 489 | * |
||
| 490 | * @param string $type Name of the calendar to caculate leap year |
||
| 491 | * |
||
| 492 | * @return boolean |
||
| 493 | */ |
||
| 494 | public function leap() |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Caculate day of year or week |
||
| 505 | * |
||
| 506 | * @since Aug, 22 2015 |
||
| 507 | * |
||
| 508 | * @return integer |
||
| 509 | */ |
||
| 510 | public function dayOf() |
||
| 518 | |||
| 519 | // public function events() |
||
| 520 | // { |
||
| 521 | // |
||
| 522 | // if (Datium::$call_type == 'between' ) { |
||
| 523 | // |
||
| 524 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
| 525 | // |
||
| 526 | // } else { |
||
| 527 | // |
||
| 528 | // $this->events = new Events($this->date_time); |
||
| 529 | // |
||
| 530 | // } |
||
| 531 | // |
||
| 532 | // return $this->events; |
||
| 533 | // |
||
| 534 | // } |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Return Datetime as a original object |
||
| 538 | * |
||
| 539 | * @since Oct 22, 2015 |
||
| 540 | * |
||
| 541 | * @return object |
||
| 542 | */ |
||
| 543 | public function object() |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Translate current date string to selected language |
||
| 552 | * |
||
| 553 | * @param string $language language short name fa, en, ar ... |
||
| 554 | * |
||
| 555 | * @return object |
||
| 556 | */ |
||
| 557 | public function lang($language = 'fa') |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Return object as timestamp |
||
| 574 | * |
||
| 575 | * @return timestamp |
||
| 576 | */ |
||
| 577 | public function timestamp() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Return fainal result |
||
| 586 | * |
||
| 587 | * @param string $format Date format |
||
| 588 | * |
||
| 589 | * @since Aug 17 2015 |
||
| 590 | * |
||
| 591 | * @return string |
||
| 592 | */ |
||
| 593 | public function get($format = 'Y-m-d H:i:s') |
||
| 656 | } |
||
| 657 |
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.