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 |
||
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 | 'tokenize' => (bool) $this->getCreateToken(), |
||
118 | 'transactionChannel' => $this->getTransactionChannel() ?? 'ECOMMERCE', |
||
119 | ], |
||
120 | 'hostedCheckoutSpecificInput' => [ |
||
121 | // if adding locale, validate locale against known formats |
||
122 | // @see https://docs.direct.worldline-solutions.com/en/integration/basic-integration-methods/hosted-checkout-page#chooselanguageversion |
||
123 | // 'locale' => 'en_UK', |
||
124 | 'returnUrl' => $this->getReturnUrl(), |
||
125 | ], |
||
126 | 'order' => [ |
||
127 | 'amountOfMoney' => [ |
||
128 | 'amount' => $this->getAmountInteger(), |
||
129 | 'currencyCode' => $this->getCurrency(), |
||
130 | ], |
||
131 | 'references' => [ |
||
132 | 'descriptor' => $this->getMerchantName(), |
||
133 | 'merchantReference' => $this->getTransactionId(), |
||
134 | ], |
||
135 | 'shoppingCart' => [ |
||
136 | 'items' => $formattedItems, |
||
137 | ], |
||
138 | ], |
||
139 | ]; |
||
140 | |||
141 | if ($this->getAvailablePaymentProducts() !== null) { |
||
142 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
143 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
144 | } |
||
145 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['restrictTo'] = [ |
||
146 | 'products' => $this->getAvailablePaymentProducts(), |
||
147 | ]; |
||
148 | } |
||
149 | |||
150 | if ($this->getExcludedPaymentProducts() !== null) { |
||
151 | if (!isset($data['hostedCheckoutSpecificInput']['paymentProductFilters'])) { |
||
152 | $data['hostedCheckoutSpecificInput']['paymentProductFilters'] = []; |
||
153 | } |
||
154 | $data['hostedCheckoutSpecificInput']['paymentProductFilters']['exclude'] = [ |
||
155 | 'products' => $this->getExcludedPaymentProducts(), |
||
156 | ]; |
||
157 | } |
||
158 | |||
159 | if ($this->getShowResultPage() !== null) { |
||
160 | $data['hostedCheckoutSpecificInput']['showResultPage'] = (bool) $this->getShowResultPage(); |
||
161 | } |
||
162 | |||
163 | if ($this->getSessionTimeout() !== null) { |
||
164 | $data['hostedCheckoutSpecificInput']['sessionTimeout'] = (int) $this->getSessionTimeout(); |
||
165 | } |
||
166 | |||
167 | if ($this->getToken() !== null || $this->getCardReference() !== null) { |
||
|
|||
168 | $data['cardPaymentMethodSpecificInput']['token'] = $this->getToken() ?? $this->getCardReference(); |
||
169 | } |
||
170 | |||
171 | if ($this->getNotifyUrl() !== null) { |
||
172 | $data['feedbacks'] = [ |
||
173 | 'webhookUrl' => $this->getNotifyUrl(), |
||
174 | ]; |
||
175 | } |
||
176 | |||
177 | return $data; |
||
178 | } |
||
190 |