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 Address extends USPSLookup |
||
8 | { |
||
9 | /** |
||
10 | * Verify Address is current and/or inhabited |
||
11 | * @param $address |
||
12 | * @param $address2 |
||
13 | * @param $city |
||
14 | * @param $state |
||
15 | * @param $zip |
||
16 | * @return object |
||
17 | */ |
||
18 | public static function verify($address,$address2,$city,$state,$zip): object |
||
34 | |||
35 | /** |
||
36 | * City and State lookup from zipcode. |
||
37 | * @param $zip |
||
38 | * @return \SimpleXMLElement |
||
39 | */ |
||
40 | View Code Duplication | public static function cityState($zip): object |
|
50 | |||
51 | /** |
||
52 | * Mulitple city and state lookup |
||
53 | * @param $zip (array) |
||
54 | * @return \SimpleXMLElement |
||
55 | */ |
||
56 | public static function cityStateMultiple($zip): object |
||
68 | |||
69 | /** |
||
70 | * Zipcode lookup by Address, City, and State |
||
71 | * @param $address |
||
72 | * @param $address2 |
||
73 | * @param $city |
||
74 | * @param $state |
||
75 | * @return \SimpleXMLElement |
||
76 | */ |
||
77 | public static function zipCode($address,$address2,$city,$state): object |
||
90 | } |
||
91 |
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.