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 |
||
8 | class TelematicsVendor extends Common |
||
9 | { |
||
10 | public $vendor_id; // Telematics Vendor id |
||
11 | public $is_integrated; // If 1, the vendor is integrated in Route4Me |
||
12 | public $page; // starting page |
||
13 | public $per_page; // Vendors per page in a response |
||
14 | public $country; // Country Alpha 2 code |
||
15 | public $feature; // Vendor's feature |
||
16 | public $search; // Searched text |
||
17 | public $vendors; // Comma-delimited list of the vendors IDs. |
||
18 | |||
19 | public static function fromArray(array $params) { |
||
30 | |||
31 | View Code Duplication | public static function GetTelematicsVendors($params) { |
|
44 | |||
45 | public static function GetRandomVendorID($offset, $limit) { |
||
66 | |||
67 | /* |
||
68 | public static function GetTelematicsVendor($params) { |
||
69 | Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS); |
||
70 | |||
71 | $allQueryFields = array('vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors'); |
||
72 | |||
73 | $query = Route4Me::generateRequestParameters($allQueryFields, $params); |
||
74 | |||
75 | $vendors = Route4Me::makeRequst(array( |
||
76 | 'url' => "", |
||
77 | 'method' => 'GET', |
||
78 | 'query' => Route4Me::generateRequestParameters($allQueryFields, $params) |
||
79 | )); |
||
80 | |||
81 | return $vendors; |
||
82 | } |
||
83 | */ |
||
84 | |||
85 | } |
||
86 |
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.