| 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 | ||
| 91 | public function getData() | ||
| 92 |     { | ||
| 93 |         $this->validate('merchantId', 'amount', 'currency'); | ||
| 94 | |||
| 95 | $formattedItems = []; | ||
| 96 | $items = $this->getItems(); | ||
| 97 |         if ($items) { | ||
| 98 |             foreach ($items as $item) { | ||
| 99 | $itemPrice = $this->getItemPriceInteger($item); | ||
| 100 | $formattedItems[] = [ | ||
| 101 | 'amountOfMoney' => [ | ||
| 102 | 'amount' => $item->getQuantity() * $itemPrice, | ||
| 103 | 'currencyCode' => $this->getCurrency(), | ||
| 104 | ], | ||
| 105 | 'orderLineDetails' => [ | ||
| 106 | 'productName' => $item->getName(), | ||
| 107 | 'productPrice' => $itemPrice, | ||
| 108 | 'quantity' => (int) $item->getQuantity(), | ||
| 109 | ], | ||
| 110 | ]; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | $data = [ | ||
| 115 | 'cardPaymentMethodSpecificInput' => [ | ||
| 116 | 'authorizationMode' => $this->authorizationMode ?? 'SALE', | ||
| 117 | 'transactionChannel' => $this->getTransactionChannel() ?? 'ECOMMERCE', | ||
| 118 | ], | ||
| 119 | 'hostedCheckoutSpecificInput' => [ | ||
| 120 | // if adding locale, validate locale against known formats | ||
| 121 | // @see https://docs.direct.worldline-solutions.com/en/integration/basic-integration-methods/hosted-checkout-page#chooselanguageversion | ||
| 122 | // 'locale' => 'en_UK', | ||
| 123 | 'returnUrl' => $this->getReturnUrl(), | ||
| 124 | ], | ||
| 125 | 'order' => [ | ||
| 126 | 'amountOfMoney' => [ | ||
| 127 | 'amount' => $this->getAmountInteger(), | ||
| 128 | 'currencyCode' => $this->getCurrency(), | ||
| 129 | ], | ||
| 130 | 'references' => [ | ||
| 131 | 'descriptor' => $this->getMerchantName(), | ||
| 132 | 'merchantReference' => $this->getTransactionId(), | ||
| 133 | ], | ||
| 134 | 'shoppingCart' => [ | ||
| 135 | 'items' => $formattedItems, | ||
| 136 | ], | ||
| 137 | ], | ||
| 138 | ]; | ||
| 139 | |||
| 140 |         if ($this->getAvailablePaymentProducts() !== null) { | ||
| 141 |             if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { | ||
| 142 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; | ||
| 143 | } | ||
| 144 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['restrictTo'] = [ | ||
| 145 | 'products' => $this->getAvailablePaymentProducts(), | ||
| 146 | ]; | ||
| 147 | } | ||
| 148 | |||
| 149 |         if ($this->getExcludedPaymentProducts() !== null) { | ||
| 150 |             if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { | ||
| 151 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; | ||
| 152 | } | ||
| 153 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['exclude'] = [ | ||
| 154 | 'products' => $this->getExcludedPaymentProducts(), | ||
| 155 | ]; | ||
| 156 | } | ||
| 157 | |||
| 158 |         if ($this->getShowResultPage() !== null) { | ||
| 159 | $data['hostedCheckoutSpecificInput']['showResultPage'] = (bool) $this->getShowResultPage(); | ||
| 160 | } | ||
| 161 | |||
| 162 |         if ($this->getSessionTimeout() !== null) { | ||
| 163 | $data['hostedCheckoutSpecificInput']['sessionTimeout'] = (int) $this->getSessionTimeout(); | ||
| 164 | } | ||
| 165 | |||
| 166 |         if ($this->getNotifyUrl() !== null) { | ||
|  | |||
| 167 | $data['feedbacks'] = [ | ||
| 168 | 'webhookUrl' => $this->getNotifyUrl(), | ||
| 169 | ]; | ||
| 170 | } | ||
| 171 | |||
| 172 | return $data; | ||
| 173 | } | ||
| 185 |