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 |
||
10 | class Address extends Common |
||
11 | { |
||
12 | static public $apiUrl = '/api.v4/address.php'; |
||
13 | static public $apiUrlMove='/actions/route/move_route_destination.php'; |
||
14 | static public $apiUrDeparted='/api/route/mark_address_departed.php'; |
||
15 | static public $apiUrVisited='/actions/address/update_address_visited.php'; |
||
16 | |||
17 | public $route_destination_id; |
||
18 | public $alias; |
||
19 | public $member_id; |
||
20 | public $address; |
||
21 | public $is_depot = false; |
||
22 | public $lat; |
||
23 | public $lng; |
||
24 | public $route_id; |
||
25 | public $original_route_id; |
||
26 | public $optimization_problem_id; |
||
27 | public $sequence_no; |
||
28 | public $geocoded; |
||
29 | public $preferred_geocoding; |
||
30 | public $failed_geocoding; |
||
31 | public $geocodings = array(); |
||
32 | public $contact_id; |
||
33 | public $is_visited; |
||
34 | public $customer_po; |
||
35 | public $invoice_no; |
||
36 | public $reference_no; |
||
37 | public $order_no; |
||
38 | public $weight; |
||
39 | public $cost; |
||
40 | public $revenue; |
||
41 | public $cube; |
||
42 | public $pieces; |
||
43 | public $email; |
||
44 | public $phone; |
||
45 | public $destination_note_count; |
||
46 | public $drive_time_to_next_destination; |
||
47 | public $distance_to_next_destination; |
||
48 | public $generated_time_window_start; |
||
49 | public $generated_time_window_end; |
||
50 | public $time_window_start; |
||
51 | public $time_window_end; |
||
52 | public $time; |
||
53 | public $notes; |
||
54 | public $timestamp_last_visited; |
||
55 | public $custom_fields = array(); |
||
56 | public $manifest = array(); |
||
57 | |||
58 | public static function fromArray(array $params) |
||
81 | |||
82 | public static function getAddress($routeId, $addressId) |
||
95 | |||
96 | /*Get notes from the specified route destination |
||
97 | * Returns an address object with notes, if an address exists, otherwise - return null. |
||
98 | */ |
||
99 | View Code Duplication | public static function GetAddressesNotes($noteParams) |
|
113 | |||
114 | View Code Duplication | public function update() |
|
128 | |||
129 | View Code Duplication | public function markAddress($params, $body) |
|
143 | |||
144 | View Code Duplication | public function markAsDeparted($params) |
|
159 | |||
160 | View Code Duplication | public function markAsVisited($params) |
|
175 | |||
176 | View Code Duplication | public function delete() |
|
189 | |||
190 | public function MoveDestinationToRoute($params) |
||
205 | |||
206 | function getAddressId() |
||
210 | } |
||
211 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.