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 |
||
5 | class CalenderFactory extends Calender |
||
6 | { |
||
7 | /** |
||
8 | * @param string $day should match regex pattern ----\d\d |
||
9 | * |
||
10 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
11 | */ |
||
12 | View Code Duplication | public static function fromDay($day) |
|
21 | |||
22 | /** |
||
23 | * @param string $monthDay |
||
24 | * |
||
25 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
26 | */ |
||
27 | View Code Duplication | public static function fromMonthDay($monthDay) |
|
36 | |||
37 | /** |
||
38 | * @param string $month |
||
39 | * |
||
40 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
41 | */ |
||
42 | View Code Duplication | public static function fromMonth($month) |
|
51 | |||
52 | /** |
||
53 | * @param string $yearMonth |
||
54 | * |
||
55 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
56 | */ |
||
57 | View Code Duplication | public static function fromYearMonth($yearMonth) |
|
58 | { |
||
59 | $yearMonthTimezone = '/(\d{4})-((?:1[0-2])|(?:0[0-9]))([-+][0-1]\d:[0-6]\d|Z*)/'; |
||
60 | preg_match_all($yearMonthTimezone, $yearMonth, $matches, PREG_SET_ORDER, 0); |
||
61 | if (count($matches) != 1 || count($matches[0]) != 4) { |
||
62 | throw new \InvalidArgumentException('Unable to extract year month from input string'); |
||
63 | } |
||
64 | return new self($matches[0][1], $matches[0][2], null, $matches[0][3]); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param string $year |
||
69 | * |
||
70 | * @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
||
71 | */ |
||
72 | View Code Duplication | public static function fromYear($year) |
|
81 | } |
||
82 |