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() |
||
| 98 | { |
||
| 99 | |||
| 100 | $this->language = 'en'; |
||
| 101 | |||
| 102 | $this->translate_from = 'gregorian'; |
||
| 103 | |||
| 104 | $this->translate_to = 'gregorian'; |
||
| 105 | |||
| 106 | $this->config = include 'Config.php'; |
||
| 107 | |||
| 108 | $this->calendar_type = $this->config[ 'default_calendar' ]; |
||
| 109 | |||
| 110 | date_default_timezone_set($this->config[ 'timezone' ]); |
||
| 111 | |||
| 112 | $this->calendar_type = 'gregorian'; |
||
| 113 | |||
| 114 | switch (Datium::$call_type) { |
||
| 115 | case 'now': |
||
| 116 | $this->date_time = new DateTime('now'); |
||
| 117 | |||
| 118 | $this->gregorian_DayofWeek = $this->date_time->format('w'); |
||
| 119 | |||
| 120 | break; |
||
| 121 | |||
| 122 | case 'make': |
||
| 123 | $this->date_time = new DateTime('now'); |
||
| 124 | |||
| 125 | $this->date_time->setDate( |
||
| 126 | self::$array_date[ 'year' ], |
||
| 127 | self::$array_date[ 'month' ], |
||
| 128 | self::$array_date[ 'day' ] |
||
| 129 | ); |
||
| 130 | |||
| 131 | $this->date_time->setTime( |
||
| 132 | self::$array_date[ 'hour' ], |
||
| 133 | self::$array_date[ 'minute' ], |
||
| 134 | self::$array_date[ 'second' ] |
||
| 135 | ); |
||
| 136 | |||
| 137 | $this->gregorian_DayofWeek = $this->date_time->format('w'); |
||
| 138 | |||
| 139 | break; |
||
| 140 | |||
| 141 | case 'set': |
||
| 142 | $this->date_time = Datium::$static_date_time; |
||
| 143 | |||
| 144 | $this->gregorian_DayofWeek = $this->date_time->format('w'); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->convert_calendar = new Convert(); |
||
| 148 | |||
| 149 | } |
||
| 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( |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Select The range between two date object |
||
| 240 | * |
||
| 241 | * @param object $date_start Start of the DateTime |
||
| 242 | * @param object $date_end End of the DateTime |
||
| 243 | * |
||
| 244 | * @return object |
||
| 245 | */ |
||
| 246 | public static function between($date_start, $date_end) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Convert from current calendar, what type is current calendar? |
||
| 261 | * |
||
| 262 | * @param object $calendar Assigned calendar to start from |
||
| 263 | * |
||
| 264 | * @return $object |
||
|
|
|||
| 265 | */ |
||
| 266 | View Code Duplication | public function from($calendar) |
|
| 284 | |||
| 285 | /** |
||
| 286 | * Convert date to current Date |
||
| 287 | * |
||
| 288 | * @param object $calendar Assigned calendar to when calendar should start. |
||
| 289 | * |
||
| 290 | * @return object |
||
| 291 | */ |
||
| 292 | View Code Duplication | public function to($calendar) |
|
| 309 | |||
| 310 | |||
| 311 | /** |
||
| 312 | * Difference between two time |
||
| 313 | * |
||
| 314 | * @param DateTime $start Start of the date |
||
| 315 | * @param DateTime $end End of the date |
||
| 316 | * |
||
| 317 | * @return object |
||
| 318 | */ |
||
| 319 | public static function diff($start, $end) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Add new date value to current date |
||
| 328 | * |
||
| 329 | * @param string $value How much date should be added to current date |
||
| 330 | * |
||
| 331 | * @return object |
||
| 332 | */ |
||
| 333 | View Code Duplication | public function add($value) |
|
| 355 | |||
| 356 | /** |
||
| 357 | * Sub date from current date |
||
| 358 | * |
||
| 359 | * @param string $value How much date should increase from current date |
||
| 360 | * |
||
| 361 | * @return obejct |
||
| 362 | */ |
||
| 363 | View Code Duplication | public function sub($value) |
|
| 385 | |||
| 386 | /** |
||
| 387 | * Check if current year is leap or not |
||
| 388 | * |
||
| 389 | * @param string $type Name of the calendar to caculate leap year |
||
| 390 | * |
||
| 391 | * @return boolean |
||
| 392 | */ |
||
| 393 | public function leap() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Caculate day of year or week |
||
| 404 | * |
||
| 405 | * @since Aug, 22 2015 |
||
| 406 | * |
||
| 407 | * @return integer |
||
| 408 | */ |
||
| 409 | public function dayOf() |
||
| 417 | |||
| 418 | // public function events() |
||
| 419 | // { |
||
| 420 | // |
||
| 421 | // if (Datium::$call_type == 'between' ) { |
||
| 422 | // |
||
| 423 | // $this->events = new Events(Datium::$date_start, Datium::$date_end); |
||
| 424 | // |
||
| 425 | // } else { |
||
| 426 | // |
||
| 427 | // $this->events = new Events($this->date_time); |
||
| 428 | // |
||
| 429 | // } |
||
| 430 | // |
||
| 431 | // return $this->events; |
||
| 432 | // |
||
| 433 | // } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Return Datetime as a original object |
||
| 437 | * |
||
| 438 | * @since Oct 22, 2015 |
||
| 439 | * |
||
| 440 | * @return object |
||
| 441 | */ |
||
| 442 | public function object() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Translate current date string to selected language |
||
| 451 | * |
||
| 452 | * @param string $language language short name fa, en, ar ... |
||
| 453 | * |
||
| 454 | * @return object |
||
| 455 | */ |
||
| 456 | public function lang($language = 'fa') |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Return object as timestamp |
||
| 473 | * |
||
| 474 | * @return timestamp |
||
| 475 | */ |
||
| 476 | public function timestamp() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Return fainal result |
||
| 485 | * |
||
| 486 | * @param string $format Date format |
||
| 487 | * |
||
| 488 | * @since Aug 17 2015 |
||
| 489 | * |
||
| 490 | * @return string |
||
| 491 | */ |
||
| 492 | public function get($format = 'Y-m-d H:i:s') |
||
| 563 | } |
||
| 564 |
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.