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 |
||
10 | class Calender |
||
|
|||
11 | { |
||
12 | const timezoneRegexPattern = '([-+][0-1]\d:[0-6]\d|Z*)'; |
||
13 | private $year; |
||
14 | private $month; |
||
15 | private $day; |
||
16 | |||
17 | private function __construct($year = null, $month = null, $day = null, $timezone = 'Z') |
||
25 | |||
26 | /** |
||
27 | * @param int $year |
||
28 | * @param int $month |
||
29 | * @param int $day |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | private function validateInput($year = null, $month = null, $day = null) |
||
42 | |||
43 | /** |
||
44 | * @return void |
||
45 | */ |
||
46 | private function valdidateState() |
||
55 | |||
56 | /** |
||
57 | * @return integer |
||
58 | */ |
||
59 | private function getMaxDays() |
||
66 | |||
67 | /** |
||
68 | * @return integer |
||
69 | */ |
||
70 | private function getYearOrHolder() |
||
77 | |||
78 | /** |
||
79 | * @param string $day should match regex pattern ----\d\d |
||
80 | * |
||
81 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
82 | */ |
||
83 | View Code Duplication | public static function fromDay($day) |
|
92 | |||
93 | /** |
||
94 | * @param string $monthDay |
||
95 | * |
||
96 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
97 | */ |
||
98 | View Code Duplication | public static function FromMonthDay($monthDay) |
|
107 | |||
108 | /** |
||
109 | * @param string $month |
||
110 | * |
||
111 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
112 | */ |
||
113 | View Code Duplication | public static function fromMonth($month) |
|
122 | |||
123 | /** |
||
124 | * @param string $yearMonth |
||
125 | * |
||
126 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
127 | */ |
||
128 | View Code Duplication | public static function fromYearMonth($yearMonth) |
|
137 | |||
138 | /** |
||
139 | * @param string $year |
||
140 | * |
||
141 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
142 | */ |
||
143 | View Code Duplication | public static function fromYear($year) |
|
152 | } |
||
153 |