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 | class DMSDocumentCartController extends Controller |
||
|
|||
4 | { |
||
5 | private static $url_handlers = array( |
||
6 | '$Action//$ID' => 'handleAction', |
||
7 | ); |
||
8 | |||
9 | private static $allowed_actions = array( |
||
10 | 'DocumentCartForm', |
||
11 | 'add', |
||
12 | 'deduct', |
||
13 | 'remove', |
||
14 | ); |
||
15 | |||
16 | /** |
||
17 | * See {@link DMSDocumentCart::getItems()} |
||
18 | * |
||
19 | * @return ArrayList |
||
20 | */ |
||
21 | public function items() |
||
22 | { |
||
23 | return $this->getCart()->getItems(); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Prepares receiver info for the template. |
||
28 | * Additionally it uses Zend_Locale to retrieve the localised spelling of the Country |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | public function getReceiverInfo() |
||
49 | |||
50 | /** |
||
51 | * See DMSDocumentCart::isCartEmpty() |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function getIsCartEmpty() |
||
59 | |||
60 | /** |
||
61 | * Add quantity to an item that exists in {@link DMSDocumentCart}. |
||
62 | * If the item does nt exist, try to add a new item of the particular |
||
63 | * class given the URL parameters available. |
||
64 | * |
||
65 | * @param SS_HTTPRequest $request |
||
66 | * |
||
67 | * @return SS_HTTPResponse|string |
||
68 | */ |
||
69 | public function add(SS_HTTPRequest $request) |
||
101 | |||
102 | /** |
||
103 | * Deduct quantity from an item that exists in {@link DMSDocumentCart} |
||
104 | * |
||
105 | * @param SS_HTTPRequest $request |
||
106 | * |
||
107 | * @return SS_HTTPResponse|string |
||
108 | */ |
||
109 | public function deduct(SS_HTTPRequest $request) |
||
126 | |||
127 | /** |
||
128 | * Completely remove an item that exists in {@link DMSDocumentCart} |
||
129 | * |
||
130 | * @param SS_HTTPRequest $request |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public function remove(SS_HTTPRequest $request) |
||
146 | |||
147 | /** |
||
148 | * Retrieves a {@link DMSDocumentCart} instance |
||
149 | * |
||
150 | * @return DMSDocumentCart |
||
151 | */ |
||
152 | public function getCart() |
||
156 | } |
||
157 |
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.