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 |
||
15 | class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction |
||
16 | { |
||
17 | |||
18 | private static $allowed_actions = array( |
||
19 | 'spam', |
||
20 | 'approve', |
||
21 | ); |
||
22 | |||
23 | private static $url_handlers = array( |
||
24 | 'spam' => 'spam', |
||
25 | 'approve' => 'approve', |
||
26 | ); |
||
27 | |||
28 | |||
29 | View Code Duplication | public function spam(SS_HTTPRequest $request) |
|
47 | |||
48 | |||
49 | View Code Duplication | public function approve(SS_HTTPRequest $request) |
|
67 | } |
||
68 |
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.