| Conditions | 12 |
| Paths | 288 |
| Total Lines | 87 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 101 | public function getData() |
||
| 102 | { |
||
| 103 | $this->validate('merchantId', 'amount', 'currency'); |
||
| 104 | |||
| 105 | $formattedItems = []; |
||
| 106 | $items = $this->getItems(); |
||
| 107 | if ($items) { |
||
| 108 | foreach ($items as $item) { |
||
| 109 | $itemPrice = $this->getItemPriceInteger($item); |
||
| 110 | $formattedItems[] = [ |
||
| 111 | 'amountOfMoney' => [ |
||
| 112 | 'amount' => $item->getQuantity() * $itemPrice, |
||
| 113 | 'currencyCode' => $this->getCurrency(), |
||
| 114 | ], |
||
| 115 | 'orderLineDetails' => [ |
||
| 116 | 'productName' => $item->getName(), |
||
| 117 | 'productPrice' => $itemPrice, |
||
| 118 | 'quantity' => (int) $item->getQuantity(), |
||
| 119 | ], |
||
| 120 | ]; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $data = [ |
||
| 125 | 'cardPaymentMethodSpecificInput' => [ |
||
| 126 | 'authorizationMode' => $this->authorizationMode ?? 'SALE', |
||
| 127 | 'tokenize' => (bool) $this->getTokenize(), |
||
| 128 | 'transactionChannel' => $this->getTransactionChannel() ?? 'ECOMMERCE', |
||
| 129 | ], |
||
| 130 | 'hostedCheckoutSpecificInput' => [ |
||
| 131 | // if adding locale, validate locale against known formats |
||
| 132 | // @see https://docs.direct.worldline-solutions.com/en/integration/basic-integration-methods/hosted-checkout-page#chooselanguageversion |
||
| 133 | // 'locale' => 'en_UK', |
||
| 134 | 'returnUrl' => $this->getReturnUrl(), |
||
| 135 | ], |
||
| 136 | 'order' => [ |
||
| 137 | 'amountOfMoney' => [ |
||
| 138 | 'amount' => $this->getAmountInteger(), |
||
| 139 | 'currencyCode' => $this->getCurrency(), |
||
| 140 | ], |
||
| 141 | 'references' => [ |
||
| 142 | 'descriptor' => $this->getMerchantName(), |
||
| 143 | 'merchantReference' => $this->getTransactionId(), |
||
| 144 | ], |
||
| 145 | 'shoppingCart' => [ |
||
| 146 | 'items' => $formattedItems, |
||
| 147 | ], |
||
| 148 | ], |
||
| 149 | ]; |
||
| 150 | |||
| 151 | if ($this->getAvailablePaymentProducts() !== null) { |
||
| 152 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
| 153 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
| 154 | } |
||
| 155 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['restrictTo'] = [ |
||
| 156 | 'products' => $this->getAvailablePaymentProducts(), |
||
| 157 | ]; |
||
| 158 | } |
||
| 159 | |||
| 160 | if ($this->getExcludedPaymentProducts() !== null) { |
||
| 161 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
| 162 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
| 163 | } |
||
| 164 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['exclude'] = [ |
||
| 165 | 'products' => $this->getExcludedPaymentProducts(), |
||
| 166 | ]; |
||
| 167 | } |
||
| 168 | |||
| 169 | if ($this->getShowResultPage() !== null) { |
||
| 170 | $data['hostedCheckoutSpecificInput']['showResultPage'] = (bool) $this->getShowResultPage(); |
||
| 171 | } |
||
| 172 | |||
| 173 | if ($this->getSessionTimeout() !== null) { |
||
| 174 | $data['hostedCheckoutSpecificInput']['sessionTimeout'] = (int) $this->getSessionTimeout(); |
||
| 175 | } |
||
| 176 | |||
| 177 | if ($this->getToken() !== null || $this->getCardReference() !== null) { |
||
|
|
|||
| 178 | $data['cardPaymentMethodSpecificInput']['token'] = $this->getToken() ?? $this->getCardReference(); |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($this->getNotifyUrl() !== null) { |
||
| 182 | $data['feedbacks'] = [ |
||
| 183 | 'webhookUrl' => $this->getNotifyUrl(), |
||
| 184 | ]; |
||
| 185 | } |
||
| 186 | |||
| 187 | return $data; |
||
| 188 | } |
||
| 200 |