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 | * @var object |
||
12 | */ |
||
13 | protected $date_time; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $config; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $calendar_type; |
||
24 | |||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $day_of_week; |
||
29 | |||
30 | /** |
||
31 | * Constructor of DayOf class |
||
32 | */ |
||
33 | public function __construct($date_time, $calendar_type = 'gregorian', $day_of_week = null) |
||
47 | |||
48 | /** |
||
49 | * Which day of year is current day. |
||
50 | * |
||
51 | * @since Aug, 03 2015 |
||
52 | * @return integer |
||
53 | */ |
||
54 | public function year() |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Which day of week is current day. |
||
64 | * |
||
65 | * @since Aug, 09 2015 |
||
66 | * @return integer |
||
67 | */ |
||
68 | public function week() |
||
73 | |||
74 | /** |
||
75 | * Return last day of current month |
||
76 | * |
||
77 | * @since Oct, 18 2016 |
||
78 | * @return integer |
||
79 | */ |
||
80 | public function lastDayMonth() { |
||
115 | } |
||
116 |