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 |
||
35 | class Consumerscore extends \Payone\Core\Helper\Base |
||
36 | { |
||
37 | const CONFIG_KEY_CONSUMERSCORE_SAMPLE_COUNTER = 'payone_consumerscore_sample_counter'; |
||
38 | |||
39 | /** |
||
40 | * Config writer resource |
||
41 | * |
||
42 | * @var \Magento\Framework\App\Config\Storage\WriterInterface |
||
43 | */ |
||
44 | protected $configWriter; |
||
45 | |||
46 | /** |
||
47 | * PAYONE database helper |
||
48 | * |
||
49 | * @var \Payone\Core\Helper\Database |
||
50 | */ |
||
51 | protected $databaseHelper; |
||
52 | |||
53 | /** |
||
54 | * Constructor |
||
55 | * |
||
56 | * @param \Magento\Framework\App\Helper\Context $context |
||
57 | * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
||
58 | * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter |
||
59 | * @param \Payone\Core\Helper\Database $databaseHelper |
||
60 | */ |
||
61 | public function __construct( |
||
71 | |||
72 | /** |
||
73 | * Retrieve the creditrating sample counter from config |
||
74 | * |
||
75 | * @return int |
||
76 | */ |
||
77 | public function getConsumerscoreSampleCounter() |
||
89 | |||
90 | /** |
||
91 | * Store new value for creditrating sample counter in config |
||
92 | * |
||
93 | * @param $iCount |
||
94 | * @return true |
||
95 | */ |
||
96 | public function setConsumerscoreSampleCounter($iCount) |
||
106 | |||
107 | /** |
||
108 | * Increment creditrating sample counter in config |
||
109 | * |
||
110 | * @return int Returns the new counter value |
||
111 | */ |
||
112 | public function incrementConsumerscoreSampleCounter() |
||
120 | |||
121 | /** |
||
122 | * Determine if a consumerscore sample has to be taken |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function isSampleNeeded() |
||
137 | |||
138 | /** |
||
139 | * Return if the consumerscore hint text has to be shown on payment selection |
||
140 | * |
||
141 | * @return bool |
||
142 | */ |
||
143 | View Code Duplication | public function canShowPaymentHintText() |
|
152 | |||
153 | /** |
||
154 | * Return if the consumerscore agreement message has to be shown on payment selection |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | View Code Duplication | public function canShowAgreementMessage() |
|
167 | |||
168 | /** |
||
169 | * Get worst score |
||
170 | * |
||
171 | * @param array $aScores |
||
172 | * @return string |
||
173 | */ |
||
174 | public function getWorstScore($aScores) |
||
185 | |||
186 | /** |
||
187 | * Get the allowed methods for the score and transform it into an array |
||
188 | * |
||
189 | * @param string $sScore |
||
190 | * @return array |
||
191 | */ |
||
192 | public function getAllowedMethodsForScore($sScore) |
||
207 | |||
208 | /** |
||
209 | * Copy the status of old creditrating checks to the new addresses |
||
210 | * when the lifetime of the old check was still active |
||
211 | * |
||
212 | * @param AddressInterface $oAddress |
||
213 | * @return void |
||
214 | */ |
||
215 | public function copyOldStatusToNewAddress(AddressInterface $oAddress) |
||
222 | |||
223 | /** |
||
224 | * Determine if the given quote total needs a consumerscore check |
||
225 | * |
||
226 | * @param double $dTotal |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function isCheckNeededForPrice($dTotal) |
||
238 | |||
239 | /** |
||
240 | * Base checks if a creditrating check is needed |
||
241 | * |
||
242 | * @param string $sIntegrationEvent |
||
243 | * @param double $dGrandTotal |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function isCreditratingNeeded($sIntegrationEvent, $dGrandTotal) |
||
265 | } |
||
266 |
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.