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 Addresscheck extends AddressRequest |
||
35 | { |
||
36 | /* |
||
37 | * Array of valid countries for addresscheck basic |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $aValidCountrys = [ |
||
42 | 'BE', |
||
43 | 'DK', |
||
44 | 'DE', |
||
45 | 'FI', |
||
46 | 'FR', |
||
47 | 'IT', |
||
48 | 'CA', |
||
49 | 'LU', |
||
50 | 'NL', |
||
51 | 'NO', |
||
52 | 'AT', |
||
53 | 'PL', |
||
54 | 'PT', |
||
55 | 'SE', |
||
56 | 'CH', |
||
57 | 'SK', |
||
58 | 'ES', |
||
59 | 'CZ', |
||
60 | 'HU', |
||
61 | 'US', |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * Checked addresses resource model |
||
66 | * |
||
67 | * @var \Payone\Core\Model\ResourceModel\CheckedAddresses |
||
68 | */ |
||
69 | protected $addressesChecked; |
||
70 | |||
71 | /** |
||
72 | * Constructor |
||
73 | * |
||
74 | * @param \Payone\Core\Helper\Shop $shopHelper |
||
75 | * @param \Payone\Core\Helper\Environment $environmentHelper |
||
76 | * @param \Payone\Core\Helper\Api $apiHelper |
||
77 | * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog |
||
78 | * @param \Payone\Core\Helper\Customer $customerHelper |
||
79 | * @param \Payone\Core\Model\ResourceModel\CheckedAddresses $addressesChecked |
||
80 | */ |
||
81 | View Code Duplication | public function __construct( |
|
92 | |||
93 | /** |
||
94 | * Get addresscheck type |
||
95 | * |
||
96 | * @param bool $blIsBillingAddress |
||
97 | * @return string |
||
98 | */ |
||
99 | protected function getAddresscheckType($blIsBillingAddress) |
||
107 | |||
108 | /** |
||
109 | * Check if the addresscheck is available for the given check-type and address-country |
||
110 | * |
||
111 | * @param string $sAddresscheckType |
||
112 | * @param \Magento\Quote\Api\Data\AddressInterface $oAddress |
||
113 | * @return bool |
||
114 | */ |
||
115 | protected function validateTypeToCountry($sAddresscheckType, \Magento\Quote\Api\Data\AddressInterface $oAddress) |
||
127 | |||
128 | /** |
||
129 | * Check enabled status |
||
130 | * |
||
131 | * @param bool $blIsBillingAddress |
||
132 | * @return bool |
||
133 | */ |
||
134 | protected function isCheckEnabled($blIsBillingAddress) |
||
147 | |||
148 | /** |
||
149 | * Send request "addresscheck" to PAYONE server API |
||
150 | * |
||
151 | * @param \Magento\Quote\Api\Data\AddressInterface $oAddress |
||
152 | * @param bool $blIsBillingAddress |
||
153 | * @return array|bool |
||
154 | */ |
||
155 | public function sendRequest(\Magento\Quote\Api\Data\AddressInterface $oAddress, $blIsBillingAddress = false) |
||
182 | } |
||
183 |
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.