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  | 
            ||
| 4 | class Calender  | 
            ||
| 5 | { | 
            ||
| 6 | private $year;  | 
            ||
| 7 | private $month;  | 
            ||
| 8 | private $day;  | 
            ||
| 9 | private $timeZone;  | 
            ||
| 10 | |||
| 11 | /**  | 
            ||
| 12 | * Calender constructor.  | 
            ||
| 13 | *  | 
            ||
| 14 | * @param string|null $year  | 
            ||
| 15 | * @param string|null $month  | 
            ||
| 16 | * @param string|null $day  | 
            ||
| 17 | * @param string|null $timezone  | 
            ||
| 18 | */  | 
            ||
| 19 | protected function __construct($year = null, $month = null, $day = null, $timezone = null)  | 
            ||
| 28 | |||
| 29 | /**  | 
            ||
| 30 | * @param string|null $year  | 
            ||
| 31 | * @param string|null $month  | 
            ||
| 32 | * @param string|null $day  | 
            ||
| 33 | *  | 
            ||
| 34 | * @return void  | 
            ||
| 35 | */  | 
            ||
| 36 | private function validateInput($year, $month, $day)  | 
            ||
| 41 | |||
| 42 | private function validateInputNotAllNull($year, $month, $day)  | 
            ||
| 48 | |||
| 49 | private function validateInputNotYearAndDay($year, $month, $day)  | 
            ||
| 55 | |||
| 56 | /**  | 
            ||
| 57 | * @return void  | 
            ||
| 58 | */  | 
            ||
| 59 | private function validateState()  | 
            ||
| 64 | |||
| 65 | /**  | 
            ||
| 66 | * @return void  | 
            ||
| 67 | */  | 
            ||
| 68 | private function validateDay()  | 
            ||
| 74 | |||
| 75 | /**  | 
            ||
| 76 | * @return string  | 
            ||
| 77 | */  | 
            ||
| 78 | private function getMaxDays()  | 
            ||
| 85 | |||
| 86 | /**  | 
            ||
| 87 | * @return string  | 
            ||
| 88 | */  | 
            ||
| 89 | private function getYearOrHolder()  | 
            ||
| 96 | |||
| 97 | /**  | 
            ||
| 98 | * @return void  | 
            ||
| 99 | */  | 
            ||
| 100 | private function validateMonth()  | 
            ||
| 106 | }  | 
            ||
| 107 |