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 namespace Ups\Entity; |
||
8 | class AddressValidationResponse |
||
9 | { |
||
10 | protected $response; |
||
11 | protected $requestAction; |
||
12 | |||
13 | /** |
||
14 | * AddressValidationResponse constructor. |
||
15 | * @param \SimpleXMLElement $xmlDocument |
||
16 | * @param $requestAction |
||
17 | */ |
||
18 | 14 | public function __construct(\SimpleXMLElement $xmlDocument,$requestAction) |
|
23 | |||
24 | /** |
||
25 | * Tells whether or not the NoCandidatesIndicator is present on the XML document. |
||
26 | * This indicator is returned if the address is so badly formed that UPS is |
||
27 | * unable to even offer any suggested alternatives |
||
28 | * |
||
29 | * @return bool |
||
30 | */ |
||
31 | 5 | View Code Duplication | public function noCandidates() |
38 | |||
39 | /** |
||
40 | * Tells whether or not the ValidAddressIndicator is present on the XML document. |
||
41 | * This indicator is present if provided address is valid and represents a |
||
42 | * single, unique address in the UPS Address Validation system. |
||
43 | * @return bool |
||
44 | */ |
||
45 | 3 | public function isValid() |
|
52 | |||
53 | /** |
||
54 | * Tells whether or not the AmbiguousAddressIndicator is present on the XML document. |
||
55 | * This indicator is present when the address provided is not specific enough to |
||
56 | * be unique to one physical location, but provides enough |
||
57 | * |
||
58 | * @throws \BadMethodCallException |
||
59 | * @return bool |
||
60 | */ |
||
61 | 3 | View Code Duplication | public function isAmbiguous() |
68 | |||
69 | /** |
||
70 | * @throws \BadMethodCallException |
||
71 | * @return AddressClassification |
||
72 | */ |
||
73 | 2 | public function getAddressClassification() |
|
80 | |||
81 | /** |
||
82 | * @return \Ups\Entity\AddressValidation\Address[] |
||
83 | */ |
||
84 | 1 | public function getCandidateAddressList() |
|
95 | |||
96 | 1 | public function getValidatedAddress() |
|
104 | } |