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 |
||
7 | class Vehicle extends Common |
||
8 | { |
||
9 | public $vehicle_id; |
||
10 | public $member_id; |
||
11 | public $is_deleted; |
||
12 | public $vehicle_alias; |
||
13 | public $vehicle_vin; |
||
14 | public $vehicle_reg_state_id; |
||
15 | public $vehicle_reg_country_id; |
||
16 | public $vehicle_license_plate; |
||
17 | public $vehicle_type_id; |
||
18 | public $vehicle_make; |
||
19 | public $vehicle_model_year; |
||
20 | public $vehicle_model; |
||
21 | public $vehicle_year_acquired; |
||
22 | public $vehicle_cost_new; |
||
23 | public $purchased_new; |
||
24 | public $license_start_date; |
||
25 | public $license_end_date; |
||
26 | public $vehicle_axle_count; |
||
27 | public $is_operational; |
||
28 | public $mpg_city; |
||
29 | public $mpg_highway; |
||
30 | public $fuel_type; |
||
31 | public $height_inches; |
||
32 | public $weight_lb; |
||
33 | public $external_telematics_vehicle_id; |
||
34 | public $has_trailer; |
||
35 | public $heightInInches; |
||
36 | public $lengthInInches; |
||
37 | public $widthInInches; |
||
38 | public $maxWeightPerAxleGroupInPounds; |
||
39 | public $numAxles; |
||
40 | public $weightInPounds; |
||
41 | public $HazmatType; |
||
42 | public $LowEmissionZonePref; |
||
43 | public $Use53FootTrailerRouting; |
||
44 | public $UseNationalNetwork; |
||
45 | public $UseTruckRestrictions; |
||
46 | public $AvoidFerries; |
||
47 | public $DividedHighwayAvoidPreference; |
||
48 | public $FreewayAvoidPreference; |
||
49 | public $InternationalBordersOpen; |
||
50 | public $TollRoadUsage; |
||
51 | public $hwy_only; |
||
52 | public $long_combination_vehicle; |
||
53 | public $avoid_highways; |
||
54 | public $side_street_adherence; |
||
55 | public $truck_config; |
||
56 | public $height_metric; |
||
57 | public $length_metric; |
||
58 | public $width_metric; |
||
59 | public $weight_metric; |
||
60 | public $max_weight_per_axle_group_metric; |
||
61 | |||
62 | public function __construct () |
||
66 | |||
67 | public static function fromArray(array $params) { |
||
77 | |||
78 | View Code Duplication | public static function getVehicles($params) |
|
92 | |||
93 | public function getRandomVehicleId($page,$perPage) |
||
109 | |||
110 | View Code Duplication | public function getVehicleByID($vehicleID) |
|
119 | |||
120 | public function updateVehicle($params) |
||
146 | |||
147 | View Code Duplication | public function createVehicle($params) |
|
171 | |||
172 | public function removeVehicle($params) |
||
184 | } |
||
185 |
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.