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 |
||
34 | class EncryptParameter extends Parameter |
||
35 | { |
||
36 | protected $parametersName = array( |
||
37 | // Mandatory parameters |
||
38 | 'shopLogin', |
||
39 | 'uicCode', |
||
40 | 'amount', |
||
41 | 'shopTransactionId', |
||
42 | // Optional parameters |
||
43 | 'buyerName', |
||
44 | 'buyerEmail', |
||
45 | 'languageId', |
||
46 | 'customInfo', |
||
47 | 'requestToken', |
||
48 | //'cardNumber', //deprecated |
||
49 | //'expiryMonth', //deprecated |
||
50 | //'expiryYear', //deprecated |
||
51 | //'cvv', //deprecated |
||
52 | |||
53 | /* to be implemented |
||
|
|||
54 | 'ppSellerProtection', |
||
55 | 'shippingDetails', |
||
56 | 'paymentTypes', |
||
57 | 'paymentTypeDetail', |
||
58 | 'redFraudPrevention', |
||
59 | 'Red_CustomerInfo', |
||
60 | 'Red_ShippingInfo', |
||
61 | 'Red_BillingInfo', |
||
62 | 'Red_CustomerData', |
||
63 | 'Red_CustomInfo', |
||
64 | 'Red_Items', |
||
65 | 'Consel_MerchantPro', |
||
66 | 'Consel_CustomerInfo', |
||
67 | 'payPalBillingAgreementDescription' |
||
68 | */ |
||
69 | ); |
||
70 | protected $mandatoryParameters = array( |
||
71 | 'shopLogin', |
||
72 | 'uicCode', |
||
73 | 'amount', |
||
74 | 'shopTransactionId', |
||
75 | ); |
||
76 | protected $separator = '*P1*'; |
||
77 | private $customInfoArray = array(); |
||
78 | private $invalidChars = array( |
||
79 | '&', |
||
80 | ' ', |
||
81 | '§', //need also to be added programmatically, because UTF-8 |
||
82 | '(', |
||
83 | ')', |
||
84 | '*', |
||
85 | '<', |
||
86 | '>', |
||
87 | ',', |
||
88 | ';', |
||
89 | ':', |
||
90 | '*P1*', |
||
91 | '/', |
||
92 | '[', |
||
93 | ']', |
||
94 | '?', |
||
95 | '=', |
||
96 | '--', |
||
97 | '/*', |
||
98 | '%', |
||
99 | '//', |
||
100 | ); |
||
101 | private $invalidCharsFlattened = ''; |
||
102 | |||
103 | /** |
||
104 | * @param array $parameters |
||
105 | */ |
||
106 | 31 | public function __construct(array $parameters = array()) |
|
112 | |||
113 | /** |
||
114 | * @param string $key |
||
115 | * @param mixed $value |
||
116 | */ |
||
117 | 31 | View Code Duplication | public function set($key, $value) |
125 | |||
126 | /** |
||
127 | * @param mixed $customInfo string already encoded or array of key/value to be encoded |
||
128 | */ |
||
129 | 7 | public function setCustomInfo($customInfo) |
|
150 | |||
151 | /** |
||
152 | * @return array |
||
153 | */ |
||
154 | 2 | View Code Duplication | public function getCustomInfoToArray() |
165 | |||
166 | /** |
||
167 | * @param $value |
||
168 | * @return bool |
||
169 | */ |
||
170 | 31 | public function verifyParameterValidity($value) |
|
186 | } |
||
187 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.