| Total Complexity | 45 |
| Total Lines | 262 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PurchaseRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PurchaseRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class PurchaseRequest extends AbstractRequest { |
||
| 15 | |||
| 16 | const endpointTest = 'https://uat.windcave.com/api/v1'; |
||
| 17 | const endpointLive = 'https://sec.windcave.com/api/v1'; |
||
| 18 | |||
| 19 | public function initialize(array $parameters = []) |
||
| 20 | { |
||
| 21 | return parent::initialize($parameters); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function setApiUsername($value) |
||
| 25 | { |
||
| 26 | return $this->setParameter('apiUsername', $value); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getApiUsername() |
||
| 30 | { |
||
| 31 | return $this->getParameter('apiUsername'); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function setApiKey($value) |
||
| 35 | { |
||
| 36 | return $this->setParameter('apiKey', $value); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function getApiKey() |
||
| 40 | { |
||
| 41 | return $this->getParameter('apiKey'); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function setMerchantReference($value) |
||
| 45 | { |
||
| 46 | return $this->setParameter('merchantReference', $value); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getMerchantReference() |
||
| 50 | { |
||
| 51 | return $this->getParameter('merchantReference'); |
||
| 52 | } |
||
| 53 | |||
| 54 | public function setType($value) |
||
| 55 | { |
||
| 56 | return $this->setParameter('type', $value); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function getType() |
||
| 60 | { |
||
| 61 | return $this->getParameter('type') ?? 'purchase'; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function setLanguage($value) |
||
| 65 | { |
||
| 66 | return $this->setParameter('language', $value); |
||
| 67 | } |
||
| 68 | |||
| 69 | public function getLanguage() |
||
| 70 | { |
||
| 71 | return $this->getParameter('language') ?? 'en'; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param $list |
||
| 76 | * Possible methods: ['card', 'account2account', 'alipay', 'applepay', 'googlepay', 'paypal', 'interac', 'unionpay', 'oxipay', 'visacheckout', 'wechat'] |
||
| 77 | * |
||
| 78 | * @return PurchaseRequest |
||
| 79 | */ |
||
| 80 | public function setPaymentMethods($list) |
||
| 81 | { |
||
| 82 | $options = [ |
||
| 83 | 'card', 'account2account', 'alipay', 'applepay', |
||
| 84 | 'googlepay', 'paypal', 'interac', 'unionpay', |
||
| 85 | 'oxipay', 'visacheckout', 'wechat' |
||
| 86 | ]; |
||
| 87 | |||
| 88 | foreach ( $list as $method ) { |
||
| 89 | if ( !in_array($method, $options) ) { |
||
| 90 | throw new InvalidRequestException("Unknown payment method: {$method}"); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | return $this->setParameter('paymentMethods', $list); |
||
| 95 | } |
||
| 96 | |||
| 97 | public function getPaymentMethods() |
||
| 98 | { |
||
| 99 | return $this->getParameter('paymentMethods'); |
||
| 100 | } |
||
| 101 | |||
| 102 | public function setCardTypes($list) |
||
| 103 | { |
||
| 104 | return $this->setParameter('cardTypes', $list); |
||
| 105 | } |
||
| 106 | |||
| 107 | public function getCardTypes() |
||
| 108 | { |
||
| 109 | return $this->getParameter('cardTypes'); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function setExpiresAt($value) |
||
| 113 | { |
||
| 114 | return $this->setParameter('expiresAt', $value); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getExpiresAt() |
||
| 118 | { |
||
| 119 | return $this->getParameter('expiresAt'); |
||
| 120 | } |
||
| 121 | |||
| 122 | public function setDeclineUrl($url) |
||
| 123 | { |
||
| 124 | return $this->setParameter('declineUrl', $url); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function getDeclineUrl() |
||
| 128 | { |
||
| 129 | return $this->getParameter('declineUrl'); |
||
| 130 | } |
||
| 131 | |||
| 132 | public function setStoreCard($value) |
||
| 133 | { |
||
| 134 | return $this->setParameter('storeCard', $value); |
||
| 135 | } |
||
| 136 | |||
| 137 | public function getStoreCard() |
||
| 140 | } |
||
| 141 | |||
| 142 | public function setStoredCardIndicator($value) |
||
| 143 | { |
||
| 144 | $options = [ |
||
| 145 | 'single', 'recurringfixed', 'recurringvariable', 'installment', |
||
| 146 | 'recurringnoexpiry', 'recurringinitial', 'installmentinitial', 'credentialonfileinitial', |
||
| 147 | 'unscheduledcredentialonfileinitial', 'credentialonfile', 'unscheduledcredentialonfile', 'incremental', |
||
| 148 | 'resubmission', 'reauthorisation', 'delayedcharges', 'noshow' |
||
| 149 | ]; |
||
| 150 | |||
| 151 | if ( ! in_array($value, $options) ) { |
||
| 152 | throw new InvalidRequestException("Invalid option '{$value}' set for StoredCardIndicator."); |
||
| 153 | } |
||
| 154 | |||
| 155 | return $this->setParameter('storeCardIndicator', $value); |
||
| 156 | } |
||
| 157 | |||
| 158 | public function getStoredCardIndicator() |
||
| 161 | } |
||
| 162 | |||
| 163 | public function setMetadata($data) |
||
| 164 | { |
||
| 165 | return $this->setParameter('metaData', $data); |
||
| 166 | } |
||
| 167 | |||
| 168 | public function getMetadata() |
||
| 169 | { |
||
| 170 | return $this->getParameter('metaData'); |
||
| 171 | } |
||
| 172 | |||
| 173 | public function setRecurringFrequency($value) |
||
| 174 | { |
||
| 175 | $options = [ |
||
| 176 | 'daily', 'weekly', 'every2weeks', 'every4weeks', |
||
| 177 | 'monthly', 'monthly28th', 'monthlylastcalendarday', |
||
| 178 | 'monthlysecondlastcalendarday', 'monthlythirdlastcalendarday', |
||
| 179 | 'twomonthly', 'threemonthly', 'fourmonthly', 'sixmonthly', 'annually' |
||
| 180 | ]; |
||
| 181 | |||
| 182 | if ( ! in_array($value, $options) ) { |
||
| 183 | throw new InvalidRequestException("Invalid option '{$value}' set for RecurringFrequency."); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $this->setParameter('recurringFrequency', $value); |
||
| 187 | } |
||
| 188 | |||
| 189 | public function getRecurringFrequency() |
||
| 192 | } |
||
| 193 | |||
| 194 | public function getData() |
||
| 195 | { |
||
| 196 | $this->validate('apiUsername', 'apiKey', 'amount', 'currency'); |
||
| 197 | |||
| 198 | $data = []; |
||
| 199 | |||
| 200 | $data['type'] = $this->getType(); |
||
| 201 | $data['amount'] = $this->getAmount(); |
||
| 202 | $data['currency'] = $this->getCurrency(); |
||
| 203 | $data['storeCard'] = (bool) $this->getStoreCard() ?? false; |
||
| 204 | $data['callbackUrls'] = []; |
||
| 205 | |||
| 206 | if ( is_array($this->getPaymentMethods()) ) { |
||
| 207 | $data['methods'] = $this->getPaymentMethods(); |
||
| 208 | } |
||
| 209 | |||
| 210 | if ( is_array($this->getCardTypes()) ) { |
||
| 211 | $data['cardTypes'] = $this->getCardTypes(); |
||
| 212 | } |
||
| 213 | |||
| 214 | if ( is_array($this->getMetadata()) ) { |
||
| 215 | $data['metaData'] = $this->getMetadata(); |
||
| 216 | } |
||
| 217 | |||
| 218 | if ( $this->getMerchantReference() ) { |
||
| 219 | $data['merchantReference'] = $this->getMerchantReference(); |
||
| 220 | } |
||
| 221 | |||
| 222 | if ( $this->getReturnUrl() ) { |
||
| 223 | $data['callbackUrls']['approved'] = $this->getReturnUrl(); |
||
| 224 | } |
||
| 225 | |||
| 226 | if ( $this->getDeclineUrl() ) { |
||
| 227 | $data['callbackUrls']['declined'] = $this->getDeclineUrl(); |
||
| 228 | } |
||
| 229 | |||
| 230 | if ( $this->getCancelUrl() ) { |
||
| 231 | $data['callbackUrls']['cancelled'] = $this->getCancelUrl(); |
||
| 232 | } |
||
| 233 | |||
| 234 | if ( $this->getNotifyUrl() ) { |
||
| 235 | $data['notificationUrl'] = $this->getNotifyUrl(); |
||
| 236 | } |
||
| 237 | |||
| 238 | return $data; |
||
| 239 | } |
||
| 240 | |||
| 241 | public function sendData($data) |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Get endpoint |
||
| 262 | * |
||
| 263 | * Returns endpoint depending on test mode |
||
| 264 | * |
||
| 265 | * @access protected |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | protected function getEndpoint($path = '') |
||
| 269 | { |
||
| 270 | return ($this->getTestMode() ? self::endpointTest : self::endpointLive) . '/' . $path; |
||
| 271 | } |
||
| 272 | |||
| 273 | protected function getAuthorization() |
||
| 276 | } |
||
| 277 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths