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 | View Code Duplication | class CreateCardRequest extends AbstractRequest |
|
|
|||
11 | { |
||
12 | /** |
||
13 | * @var string; |
||
14 | */ |
||
15 | protected $requestName = 'TokenizeRequest'; |
||
16 | |||
17 | /** |
||
18 | * Returns the signature for the request. |
||
19 | * |
||
20 | * @return string base64 encoded sha1 hash of the merchantPassword, merchantId, |
||
21 | * and acquirerId. |
||
22 | */ |
||
23 | protected function generateSignature() |
||
31 | |||
32 | /** |
||
33 | * Validate and construct the data for the request |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public function getData() |
||
52 | |||
53 | /** |
||
54 | * Get the customer reference. |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getCustomerReference() |
||
62 | |||
63 | /** |
||
64 | * Set the customer reference. |
||
65 | * |
||
66 | * @param string $value |
||
67 | */ |
||
68 | public function setCustomerReference($value) |
||
72 | |||
73 | /** |
||
74 | * Returns endpoint for tokenize requests |
||
75 | * |
||
76 | * @return string Endpoint URL |
||
77 | */ |
||
78 | protected function getEndpoint() |
||
82 | |||
83 | /** |
||
84 | * Return the tokenize response object |
||
85 | * |
||
86 | * @param \SimpleXMLElement $xml Response xml object |
||
87 | * |
||
88 | * @return CreateCardResponse |
||
89 | */ |
||
90 | protected function newResponse($xml) |
||
94 | |||
95 | } |
||
96 |
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.