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 declare(strict_types=1); |
||
| 24 | class Client |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * |
||
| 28 | */ |
||
| 29 | const MSU_API_VERSION = 2; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private static $validActions = [ |
||
| 35 | |||
| 36 | 'session', |
||
| 37 | 'financialTransactions', |
||
| 38 | 'approveActions', |
||
| 39 | 'rejectActions', |
||
| 40 | 'dealer', |
||
| 41 | 'dealerPST', |
||
| 42 | 'dealerType', |
||
| 43 | 'eWallet', |
||
| 44 | 'merchant', |
||
| 45 | 'merchantUser', |
||
| 46 | 'merchantContent', |
||
| 47 | 'messageContent', |
||
| 48 | 'payByLinkPayment', |
||
| 49 | 'paymentPolicy', |
||
| 50 | 'paymentSystem', |
||
| 51 | 'paymentType', |
||
| 52 | 'recurringPayment', |
||
| 53 | 'recurringPlan', |
||
| 54 | 'recurringPlanCard' |
||
| 55 | ]; |
||
| 56 | |||
| 57 | private static $validQueryActions = [ |
||
| 58 | 'Transaction', |
||
| 59 | 'DealerTransaction', |
||
| 60 | 'SubDealerTransaction', |
||
| 61 | 'Installment', |
||
| 62 | 'Card', |
||
| 63 | 'CardExpiry', |
||
| 64 | 'Customer', |
||
| 65 | 'Session', |
||
| 66 | 'PayByLinkPayment', |
||
| 67 | 'Bin', |
||
| 68 | 'Campaign', |
||
| 69 | 'OnlineCampaign', |
||
| 70 | 'RecurringPlan', |
||
| 71 | 'PaymentSystems', |
||
| 72 | 'MerchantPaymentSystems', |
||
| 73 | 'MerchantProfile', |
||
| 74 | 'PaymentSystemData', |
||
| 75 | 'Points', |
||
| 76 | 'PaymentPolicy', |
||
| 77 | 'SplitPayment', |
||
| 78 | 'Merchant', |
||
| 79 | 'MerchantContent', |
||
| 80 | 'MerchantStatusHistory', |
||
| 81 | 'MerchantUser', |
||
| 82 | 'UserRolePermission', |
||
| 83 | 'Dealer', |
||
| 84 | 'DealerType', |
||
| 85 | 'DealerPst', |
||
| 86 | 'DealerStatusHistory', |
||
| 87 | 'MerchantUserDealers', |
||
| 88 | 'Groups', |
||
| 89 | 'ExecutiveReport', |
||
| 90 | 'TransactionRule' |
||
| 91 | ]; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var Environment |
||
| 95 | */ |
||
| 96 | private $environment; |
||
| 97 | /** |
||
| 98 | * @var GuzzleClient |
||
| 99 | */ |
||
| 100 | private $guzzleClient; |
||
| 101 | |||
| 102 | private $logger; |
||
| 103 | |||
| 104 | private static $headers = [ |
||
| 105 | 'User-Agent' => 'MerchantSafeUnipayPhpSDK/1.0', |
||
| 106 | 'Accept' => 'application/json' |
||
| 107 | ]; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | private static $possibleResponses = [ |
||
|
|
|||
| 113 | '00' => 'Approved', |
||
| 114 | '01' => 'Waiting for Approval', |
||
| 115 | '98' => 'General Error', |
||
| 116 | '99' => 'Declined' |
||
| 117 | ]; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Client constructor. |
||
| 121 | * @param Environment $environment |
||
| 122 | * @param GuzzleClient $guzzleClient |
||
| 123 | * @param LoggerInterface $logger |
||
| 124 | */ |
||
| 125 | public function __construct(Environment $environment, GuzzleClient $guzzleClient, LoggerInterface $logger) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param $name |
||
| 134 | * @param $arguments |
||
| 135 | * @throws BadMethodCallException |
||
| 136 | * @throws RequestException |
||
| 137 | * @throws InvalidArgumentException |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | public function __call(string $name, array $arguments) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param $name |
||
| 147 | * @param $arguments |
||
| 148 | * @throws BadMethodCallException |
||
| 149 | * @throws RequestException |
||
| 150 | * @throws InvalidArgumentException |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | public function query(string $name, array $arguments) |
||
| 157 | |||
| 158 | private function getCallAction(string $name, array $arguments) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param string $name |
||
| 182 | * @param array $arguments |
||
| 183 | * @param string $namespace |
||
| 184 | * @return ActionInterface |
||
| 185 | * @throws BadMethodCallException |
||
| 186 | * @throws InvalidArgumentException |
||
| 187 | */ |
||
| 188 | private function actionFactory(string $name, array $arguments, string $namespace) |
||
| 209 | |||
| 210 | private function requestAction(ActionInterface $action) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param string $actionName |
||
| 225 | * @param array $headers |
||
| 226 | * @param array $queryParams |
||
| 227 | * @throws RequestException |
||
| 228 | * @return ResponseInterface |
||
| 229 | */ |
||
| 230 | private function httpRequest(string $actionName, array $headers, array $queryParams) |
||
| 246 | } |
||
| 247 |
This check marks private properties in classes that are never used. Those properties can be removed.