| Conditions | 10 |
| Paths | 144 |
| Total Lines | 82 |
| Code Lines | 47 |
| 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 |
||
| 118 | public function getData() |
||
| 119 | { |
||
| 120 | $this->validate('merchantId', 'amount', 'currency'); |
||
| 121 | |||
| 122 | $formattedItems = []; |
||
| 123 | $items = $this->getItems(); |
||
| 124 | if ($items) { |
||
| 125 | foreach ($items as $item) { |
||
| 126 | $itemPrice = $this->getItemPriceInteger($item); |
||
| 127 | $formattedItems[] = [ |
||
| 128 | 'amountOfMoney' => [ |
||
| 129 | 'amount' => $item->getQuantity() * $itemPrice, |
||
| 130 | 'currencyCode' => $this->getCurrency(), |
||
| 131 | ], |
||
| 132 | 'orderLineDetails' => [ |
||
| 133 | 'productName' => $item->getName(), |
||
| 134 | 'productPrice' => $itemPrice, |
||
| 135 | 'quantity' => (int) $item->getQuantity(), |
||
| 136 | ], |
||
| 137 | ]; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | $data = [ |
||
| 142 | 'cardPaymentMethodSpecificInput' => [ |
||
| 143 | 'authorizationMode' => 'SALE', |
||
| 144 | 'transactionChannel' => 'ECOMMERCE', |
||
| 145 | ], |
||
| 146 | 'hostedCheckoutSpecificInput' => [ |
||
| 147 | // if adding locale, validate locale against known formats |
||
| 148 | // @see https://docs.direct.worldline-solutions.com/en/integration/basic-integration-methods/hosted-checkout-page#chooselanguageversion |
||
| 149 | // 'locale' => 'en_UK', |
||
| 150 | 'returnUrl' => $this->getReturnUrl(), |
||
| 151 | ], |
||
| 152 | 'order' => [ |
||
| 153 | 'amountOfMoney' => [ |
||
| 154 | 'amount' => $this->getAmountInteger(), |
||
| 155 | 'currencyCode' => $this->getCurrency(), |
||
| 156 | ], |
||
| 157 | 'references' => [ |
||
| 158 | 'descriptor' => $this->getMerchantName(), |
||
| 159 | 'merchantReference' => $this->getTransactionId(), |
||
| 160 | ], |
||
| 161 | 'shoppingCart' => [ |
||
| 162 | 'items' => $formattedItems, |
||
| 163 | ], |
||
| 164 | ], |
||
| 165 | ]; |
||
| 166 | |||
| 167 | if ($this->getAvailablePaymentProducts() !== null) { |
||
| 168 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
| 169 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
| 170 | } |
||
| 171 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['restrictTo'] = [ |
||
| 172 | 'products' => $this->getAvailablePaymentProducts(), |
||
| 173 | ]; |
||
| 174 | } |
||
| 175 | |||
| 176 | if ($this->getExcludedPaymentProducts() !== null) { |
||
| 177 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
| 178 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
| 179 | } |
||
| 180 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['exclude'] = [ |
||
| 181 | 'products' => $this->getExcludedPaymentProducts(), |
||
| 182 | ]; |
||
| 183 | } |
||
| 184 | |||
| 185 | if ($this->getShowResultPage() !== null) { |
||
| 186 | $data['hostedCheckoutSpecificInput']['showResultPage'] = (bool) $this->getShowResultPage(); |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($this->getSessionTimeout() !== null) { |
||
| 190 | $data['hostedCheckoutSpecificInput']['sessionTimeout'] = (int) $this->getSessionTimeout(); |
||
| 191 | } |
||
| 192 | |||
| 193 | if ($this->getNotifyUrl() !== null) { |
||
|
|
|||
| 194 | $data['feedbacks'] = [ |
||
| 195 | 'webhookUrl' => $this->getNotifyUrl(), |
||
| 196 | ]; |
||
| 197 | } |
||
| 198 | |||
| 199 | return $data; |
||
| 200 | } |
||
| 282 |