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 | * Constructor of DayOf class |
||
27 | */ |
||
28 | public function __construct($date_time, $calendar_type = 'gregorian') |
||
40 | |||
41 | /** |
||
42 | * Which day of year is current day. |
||
43 | * |
||
44 | * @since Aug, 03 2015 |
||
45 | * @return integer |
||
46 | */ |
||
47 | public function year() |
||
53 | |||
54 | |||
55 | /** |
||
56 | * Which day of week is current day. |
||
57 | * |
||
58 | * @since Aug, 09 2015 |
||
59 | * @return integer |
||
60 | */ |
||
61 | public function week() |
||
67 | |||
68 | /** |
||
69 | * Return last day of current month |
||
70 | * |
||
71 | * @since Oct, 18 2016 |
||
72 | * @return integer |
||
73 | */ |
||
74 | public function lastDayMonth() { |
||
109 | } |
||
110 |