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 |
||
9 | class SilverstripeColumnsPageControllerExtension extends Extension |
||
|
|||
10 | { |
||
11 | private static $allowed_actions = [ |
||
12 | 'myspecificpagemenuitems' => true |
||
13 | ]; |
||
14 | |||
15 | /** |
||
16 | * @return bool |
||
17 | */ |
||
18 | View Code Duplication | public function HasFullWidthContent() |
|
30 | |||
31 | /** |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function HasSideBar() |
||
53 | |||
54 | /** |
||
55 | * @param boolean $asClassName |
||
56 | * |
||
57 | * @return string | int |
||
58 | */ |
||
59 | public function NumberOfColumns($asClassName = true) |
||
82 | |||
83 | |||
84 | /** |
||
85 | * returns a data list of items that have been edited last - up to one day ago. |
||
86 | * This ensures that we do not show stuff we have just fixed up... |
||
87 | * @return DataList |
||
88 | */ |
||
89 | public function RecentlyUpdated($limit = 5) |
||
107 | |||
108 | /** |
||
109 | * Children Menu Items |
||
110 | * @return null | DataList |
||
111 | */ |
||
112 | View Code Duplication | public function InThisSection() |
|
123 | |||
124 | /** |
||
125 | * Sibling Menu Items |
||
126 | * @return null | DataList |
||
127 | */ |
||
128 | public function AlsoSee() |
||
143 | |||
144 | /** |
||
145 | * returns relevant menus items for |
||
146 | * @param SS_Request |
||
147 | * @return string (html) |
||
148 | */ |
||
149 | public function myspecificpagemenuitems($request) |
||
168 | |||
169 | |||
170 | public function IsNotHome() |
||
176 | } |
||
177 |
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.