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 |
||
3 | abstract class CalendarAbstractView extends ViewableData |
||
|
|||
4 | { |
||
5 | |||
6 | // Static |
||
7 | |||
8 | private static $names = array(); |
||
9 | |||
10 | // Attributes |
||
11 | |||
12 | private $name; |
||
13 | protected $number; |
||
14 | |||
15 | protected $containerClass; |
||
16 | protected $innerClass; |
||
17 | |||
18 | protected $viewTitle; |
||
19 | |||
20 | protected $template; |
||
21 | protected $viewTitleDelimiter = ' - '; |
||
22 | |||
23 | // Contructor |
||
24 | |||
25 | public function __construct($name, $number = 1) |
||
49 | |||
50 | // Abstract Functions |
||
51 | |||
52 | abstract public function init(); |
||
53 | |||
54 | abstract public function needsMonth(); |
||
56 | |||
57 | abstract public function Calendars(Calendar $calendar); |
||
58 | |||
59 | abstract public function prevLinkParams(Calendar $calendar); |
||
61 | |||
62 | abstract public function viewLinkParamsAndTitle(Calendar $calendar); |
||
63 | |||
64 | abstract public function getLinkParams($date); |
||
65 | |||
66 | abstract public function title(); |
||
68 | |||
69 | // Functions |
||
70 | |||
71 | public function getName() |
||
75 | |||
76 | public function setContainerClass($containerClass) |
||
84 | |||
85 | public function setViewTitle($viewTitle) |
||
89 | |||
90 | // Template Functions |
||
91 | |||
92 | public function setTemplate($template) |
||
96 | |||
97 | public function getTemplates() |
||
109 | |||
110 | public function setViewTitleDelimiter($viewTitleDelimiter) |
||
114 | |||
115 | public function NameClass() |
||
121 | |||
122 | public function showCalendar(Calendar $calendar) |
||
129 | } |
||
130 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.