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() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Return all datetime parts as an object |
||
| 168 | * |
||
| 169 | * @return object |
||
| 170 | */ |
||
| 171 | public function all() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get current datetime |
||
| 194 | * |
||
| 195 | * @since Aug 17 2015 |
||
| 196 | * @return object |
||
| 197 | */ |
||
| 198 | public static function now() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Set config |
||
| 209 | * |
||
| 210 | * @since June 28 2016 |
||
| 211 | * |
||
| 212 | * @param array $config |
||
| 213 | * |
||
| 214 | * @return $this |
||
| 215 | */ |
||
| 216 | public function setConfig($config = []) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Create new date time |
||
| 227 | * |
||
| 228 | * @param integer $year Year number |
||
| 229 | * @param integer $month month number |
||
| 230 | * @param integer $day day number |
||
| 231 | * @param integer $hour hour number |
||
| 232 | * @param integer $minute minute number |
||
| 233 | * @param integer $second second number |
||
| 234 | * |
||
| 235 | * @return object |
||
| 236 | */ |
||
| 237 | public static function create( |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Accept Timestamp as Datium initializion |
||
| 272 | * |
||
| 273 | * @param timestamp $timestamp Input timestamp value |
||
| 274 | * |
||
| 275 | * @return object |
||
| 276 | */ |
||
| 277 | public static function createTimestamp($timestamp) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Select The range between two date object |
||
| 299 | * |
||
| 300 | * @param object $date_start Start of the DateTime |
||
| 301 | * @param object $date_end End of the DateTime |
||
| 302 | * |
||
| 303 | * @return object |
||
| 304 | */ |
||
| 305 | public static function between($date_start, $date_end) |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Convert from current calendar, what type is current calendar? |
||
| 320 | * |
||
| 321 | * @param object $calendar Assigned calendar to start from |
||
| 322 | * |
||
| 323 | * @return $object |
||
|
|
|||
| 324 | */ |
||
| 325 | View Code Duplication | public function from($calendar) |
|
| 343 | |||
| 344 | /** |
||
| 345 | * Convert date to current Date |
||
| 346 | * |
||
| 347 | * @param object $calendar Assigned calendar to when calendar should start. |
||
| 348 | * |
||
| 349 | * @return object |
||
| 350 | */ |
||
| 351 | View Code Duplication | public function to($calendar) |
|
| 368 | |||
| 369 | /** |
||
| 370 | * Difference between two time |
||
| 371 | * |
||
| 372 | * @param DateTime $start Start of the date |
||
| 373 | * @param DateTime $end End of the date |
||
| 374 | * |
||
| 375 | * @return object |
||
| 376 | */ |
||
| 377 | public static function diff($start, $end) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Add new date value to current date |
||
| 402 | * |
||
| 403 | * @param string $value How much date should be added to current date |
||
| 404 | * |
||
| 405 | * @return object |
||
| 406 | */ |
||
| 407 | View Code Duplication | public function add($value) |
|
| 441 | |||
| 442 | /** |
||
| 443 | * Sub date from current date |
||
| 444 | * |
||
| 445 | * @param string $value How much date should increase from current date |
||
| 446 | * |
||
| 447 | * @return obejct |
||
| 448 | */ |
||
| 449 | View Code Duplication | public function sub($value) |
|
| 483 | |||
| 484 | /** |
||
| 485 | * Check if current year is leap or not |
||
| 486 | * |
||
| 487 | * @param string $type Name of the calendar to caculate leap year |
||
| 488 | * |
||
| 489 | * @return boolean |
||
| 490 | */ |
||
| 491 | public function leap() |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Caculate day of year or week |
||
| 502 | * |
||
| 503 | * @since Aug, 22 2015 |
||
| 504 | * |
||
| 505 | * @return integer |
||
| 506 | */ |
||
| 507 | public function dayOf() |
||
| 515 | |||
| 516 | // public function events() |
||
| 517 | // { |
||
| 518 | // |
||
| 519 | // if (Datium::$call_type == 'between' ) { |
||
| 520 | // |
||
| 521 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
| 522 | // |
||
| 523 | // } else { |
||
| 524 | // |
||
| 525 | // $this->events = new Events($this->date_time); |
||
| 526 | // |
||
| 527 | // } |
||
| 528 | // |
||
| 529 | // return $this->events; |
||
| 530 | // |
||
| 531 | // } |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Return Datetime as a original object |
||
| 535 | * |
||
| 536 | * @since Oct 22, 2015 |
||
| 537 | * |
||
| 538 | * @return object |
||
| 539 | */ |
||
| 540 | public function object() |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Translate current date string to selected language |
||
| 549 | * |
||
| 550 | * @param string $language language short name fa, en, ar ... |
||
| 551 | * |
||
| 552 | * @return object |
||
| 553 | */ |
||
| 554 | public function lang($language = 'fa') |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Return object as timestamp |
||
| 571 | * |
||
| 572 | * @return timestamp |
||
| 573 | */ |
||
| 574 | public function timestamp() |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Return fainal result |
||
| 583 | * |
||
| 584 | * @param string $format Date format |
||
| 585 | * |
||
| 586 | * @since Aug 17 2015 |
||
| 587 | * |
||
| 588 | * @return string |
||
| 589 | */ |
||
| 590 | public function get($format = 'Y-m-d H:i:s') |
||
| 651 | } |
||
| 652 |
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.