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 Address extends Common |
||
10 | { |
||
11 | public $route_destination_id; |
||
12 | public $alias; |
||
13 | public $member_id; |
||
14 | public $address; |
||
15 | public $addressUpdate; |
||
16 | public $is_depot = false; |
||
17 | public $lat; |
||
18 | public $lng; |
||
19 | public $route_id; |
||
20 | public $original_route_id; |
||
21 | public $optimization_problem_id; |
||
22 | public $sequence_no; |
||
23 | public $geocoded; |
||
24 | public $preferred_geocoding; |
||
25 | public $failed_geocoding; |
||
26 | public $geocodings = array(); |
||
27 | public $contact_id; |
||
28 | public $is_visited; |
||
29 | public $customer_po; |
||
30 | public $invoice_no; |
||
31 | public $reference_no; |
||
32 | public $order_no; |
||
33 | public $weight; |
||
34 | public $cost; |
||
35 | public $revenue; |
||
36 | public $cube; |
||
37 | public $pieces; |
||
38 | public $email; |
||
39 | public $phone; |
||
40 | public $tracking_number; |
||
41 | public $destination_note_count; |
||
42 | public $drive_time_to_next_destination; |
||
43 | public $distance_to_next_destination; |
||
44 | public $generated_time_window_start; |
||
45 | public $generated_time_window_end; |
||
46 | public $time_window_start; |
||
47 | public $time_window_end; |
||
48 | public $time; |
||
49 | public $notes; |
||
50 | public $timestamp_last_visited; |
||
51 | public $custom_fields = array(); |
||
52 | public $manifest = array(); |
||
53 | |||
54 | public $first_name; |
||
55 | public $last_name; |
||
56 | public $is_departed; |
||
57 | public $timestamp_last_departed; |
||
58 | public $order_id; |
||
59 | public $priority; |
||
60 | public $curbside_lat; |
||
61 | public $curbside_lng; |
||
62 | public $time_window_start_2; |
||
63 | public $time_window_end_2; |
||
64 | |||
65 | public static function fromArray(array $params) |
||
76 | |||
77 | public static function getAddress($routeId, $addressId) |
||
90 | |||
91 | /*Get notes from the specified route destination |
||
92 | * Returns an address object with notes, if an address exists, otherwise - return null. |
||
93 | */ |
||
94 | public static function GetAddressesNotes($noteParams) |
||
95 | { |
||
96 | $address = Route4Me::makeRequst(array( |
||
97 | 'url' => Endpoint::ADDRESS_V4, |
||
98 | 'method' => 'GET', |
||
99 | 'query' => array( |
||
100 | 'route_id' => isset($noteParams['route_id']) ? $noteParams['route_id'] : null, |
||
101 | 'route_destination_id' => isset($noteParams['route_destination_id']) |
||
102 | ? $noteParams['route_destination_id'] : null, |
||
103 | 'notes' => 1, |
||
104 | ) |
||
105 | )); |
||
106 | |||
107 | return $address; |
||
108 | } |
||
109 | |||
110 | View Code Duplication | public function update() |
|
124 | |||
125 | View Code Duplication | public function markAddress($params) |
|
139 | |||
140 | View Code Duplication | public function markAsDeparted($params) |
|
152 | |||
153 | View Code Duplication | public function markAsVisited($params) |
|
165 | |||
166 | View Code Duplication | public function deleteAddress() |
|
179 | |||
180 | View Code Duplication | public function moveDestinationToRoute($params) |
|
193 | |||
194 | public function AddAddressNote($params) |
||
209 | |||
210 | public function AddNoteFile($params) |
||
225 | |||
226 | public function createCustomNoteType($params) |
||
238 | |||
239 | View Code Duplication | public function removeCustomNoteType($params) |
|
251 | |||
252 | public function getAllCustomNoteTypes() |
||
261 | |||
262 | public function addCustomNoteToRoute($params) |
||
285 | |||
286 | function getAddressId() |
||
290 | } |
||
291 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.