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 |
||
| 34 | class Datium |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Store DateTime object |
||
| 39 | */ |
||
| 40 | protected $date_time; |
||
| 41 | |||
| 42 | protected static $static_date_time; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Store config file statements |
||
| 46 | * |
||
| 47 | * @param array |
||
| 48 | */ |
||
| 49 | protected $config; |
||
| 50 | |||
| 51 | protected $date_interval_expression; |
||
| 52 | |||
| 53 | protected static $date_start; |
||
| 54 | |||
| 55 | protected static $date_end; |
||
| 56 | |||
| 57 | protected $translate_from; |
||
| 58 | |||
| 59 | protected $translate_to; |
||
| 60 | |||
| 61 | protected $toConfig; |
||
| 62 | |||
| 63 | protected $fromConfig; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Return store day number |
||
| 67 | * |
||
| 68 | * @param integer |
||
| 69 | */ |
||
| 70 | protected $day_of; |
||
| 71 | |||
| 72 | protected $leap; |
||
| 73 | |||
| 74 | protected $events; |
||
| 75 | |||
| 76 | protected $translate; |
||
| 77 | |||
| 78 | protected $gregorian_DayofWeek; |
||
| 79 | |||
| 80 | protected $convert_calendar; |
||
| 81 | |||
| 82 | protected $calendar_type; |
||
| 83 | |||
| 84 | protected static $array_date; |
||
| 85 | |||
| 86 | protected static $call_type; |
||
| 87 | |||
| 88 | protected $translate_from_file; |
||
| 89 | |||
| 90 | protected $translate_to_file; |
||
| 91 | |||
| 92 | protected $language; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Datium class constructure |
||
| 96 | */ |
||
| 97 | public function __construct() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Return all datetime parts as an object |
||
| 153 | * |
||
| 154 | * @return object |
||
| 155 | */ |
||
| 156 | public function all() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Get current datetime |
||
| 179 | * |
||
| 180 | * @since Aug 17 2015 |
||
| 181 | * @return object |
||
| 182 | */ |
||
| 183 | public static function now() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Create new date time |
||
| 194 | * |
||
| 195 | * @param integer $year Year number |
||
| 196 | * @param integer $month month number |
||
| 197 | * @param integer $day day number |
||
| 198 | * @param integer $hour hour number |
||
| 199 | * @param integer $minute minute number |
||
| 200 | * @param integer $second second number |
||
| 201 | * |
||
| 202 | * @return object |
||
| 203 | */ |
||
| 204 | public static function create($year = 2000, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Select The range between two date object |
||
| 233 | * |
||
| 234 | * @param object $date_start Start of the DateTime |
||
| 235 | * @param object $date_end End of the DateTime |
||
| 236 | * |
||
| 237 | * @return object |
||
| 238 | */ |
||
| 239 | public static function between($date_start, $date_end) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Convert from current calendar, what type is current calendar? |
||
| 254 | * |
||
| 255 | * @param object $calendar Assigned calendar to start from |
||
| 256 | * |
||
| 257 | * @return $object |
||
|
|
|||
| 258 | */ |
||
| 259 | View Code Duplication | public function from($calendar) |
|
| 277 | |||
| 278 | /** |
||
| 279 | * Convert date to current Date |
||
| 280 | * |
||
| 281 | * @param object $calendar Assigned calendar to when calendar should start. |
||
| 282 | * |
||
| 283 | * @return object |
||
| 284 | */ |
||
| 285 | View Code Duplication | public function to($calendar) |
|
| 302 | |||
| 303 | |||
| 304 | /** |
||
| 305 | * Difference between two time |
||
| 306 | * |
||
| 307 | * @param DateTime $start Start of the date |
||
| 308 | * @param DateTime $end End of the date |
||
| 309 | * |
||
| 310 | * @return object |
||
| 311 | */ |
||
| 312 | public static function diff($start, $end) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Add new date value to current date |
||
| 321 | * |
||
| 322 | * @param string $value How much date should be added to current date |
||
| 323 | * |
||
| 324 | * @return object |
||
| 325 | */ |
||
| 326 | View Code Duplication | public function add($value) |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Sub date from current date |
||
| 351 | * |
||
| 352 | * @param string $value How much date should increase from current date |
||
| 353 | * |
||
| 354 | * @return obejct |
||
| 355 | */ |
||
| 356 | View Code Duplication | public function sub($value) |
|
| 378 | |||
| 379 | /** |
||
| 380 | * Check if current year is leap or not |
||
| 381 | * |
||
| 382 | * @param string $type Name of the calendar to caculate leap year |
||
| 383 | * |
||
| 384 | * @return boolean |
||
| 385 | */ |
||
| 386 | public function leap($type = 'gregorian') |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Caculate day of year or week |
||
| 397 | * |
||
| 398 | * @since Aug, 22 2015 |
||
| 399 | * |
||
| 400 | * @return integer |
||
| 401 | */ |
||
| 402 | public function dayOf() |
||
| 410 | |||
| 411 | // public function events() |
||
| 412 | // { |
||
| 413 | // |
||
| 414 | // if (Datium::$call_type == 'between' ) { |
||
| 415 | // |
||
| 416 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
| 417 | // |
||
| 418 | // } else { |
||
| 419 | // |
||
| 420 | // $this->events = new Events($this->date_time); |
||
| 421 | // |
||
| 422 | // } |
||
| 423 | // |
||
| 424 | // return $this->events; |
||
| 425 | // |
||
| 426 | // } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Return Datetime as a original object |
||
| 430 | * |
||
| 431 | * @since Oct 22, 2015 |
||
| 432 | * |
||
| 433 | * @return object |
||
| 434 | */ |
||
| 435 | public function object() |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Translate current date string to selected language |
||
| 444 | * |
||
| 445 | * @param string $language language short name fa, en, ar ... |
||
| 446 | * |
||
| 447 | * @return object |
||
| 448 | */ |
||
| 449 | public function lang($language = 'fa') |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Return fainal result |
||
| 466 | * |
||
| 467 | * @param string $format Date format |
||
| 468 | * |
||
| 469 | * @since Aug 17 2015 |
||
| 470 | * |
||
| 471 | * @return string |
||
| 472 | */ |
||
| 473 | public function get($format = 'Y-m-d H:i:s') |
||
| 544 | } |
||
| 545 |
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.