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 |
||
8 | class DayOf |
||
9 | { |
||
10 | |||
11 | protected $date_time; |
||
12 | |||
13 | protected $month; |
||
14 | |||
15 | protected $day; |
||
16 | |||
17 | protected $config; |
||
18 | |||
19 | protected $result; |
||
20 | |||
21 | protected $calendar_type; |
||
22 | |||
23 | protected $geregorian_DayofWeek; |
||
24 | |||
25 | public function __construct($date_time, $calendar_type = 'gregorian') |
||
37 | |||
38 | /** |
||
39 | * Which day of year is current day. |
||
40 | * |
||
41 | * @since Aug, 03 2015 |
||
42 | * @return integer |
||
43 | */ |
||
44 | View Code Duplication | public function year() |
|
52 | |||
53 | |||
54 | /** |
||
55 | * Which day of week is current day. |
||
56 | * |
||
57 | * @since Aug, 09 2015 |
||
58 | * @return integer |
||
59 | */ |
||
60 | View Code Duplication | public function week() |
|
68 | |||
69 | /** |
||
70 | * Return last day of current month |
||
71 | * |
||
72 | * @since Oct, 18 2016 |
||
73 | * @return integer |
||
74 | */ |
||
75 | View Code Duplication | public function lastDayMonth() { |
|
82 | } |
||
83 |