| Conditions | 20 | 
| Paths | 7012 | 
| Total Lines | 221 | 
| Code Lines | 176 | 
| 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 | ||
| 179 | public function pagantisReceiptPage($order_id) | ||
| 180 |     { | ||
| 181 |         try { | ||
| 182 | require_once(__ROOT__.'/vendor/autoload.php'); | ||
| 183 | $order = new WC_Order($order_id); | ||
| 184 | $order->set_payment_method(ucfirst($this->id)); | ||
| 185 | $order->save(); | ||
| 186 |             if (!isset($order)) { | ||
| 187 |                 throw new Exception(_("Order not found")); | ||
| 188 | } | ||
| 189 | |||
| 190 |             $shippingAddress = $order->get_address('shipping'); | ||
| 191 |             $billingAddress = $order->get_address('billing'); | ||
| 192 |             if ($shippingAddress['address_1'] == '') { | ||
| 193 | $shippingAddress = $billingAddress; | ||
| 194 | } | ||
| 195 | |||
| 196 | $customer_id = $order->get_customer_id(); | ||
| 197 | $national_id = maybeGetIDNumber($order , $customer_id); | ||
| 198 | $tax_id = maybeGetTaxIDNumber($order , $customer_id); | ||
| 199 | $phoneNumber = maybeGetPhoneNumber($order , $customer_id); | ||
| 200 | |||
| 201 | $userAddress = new Address(); | ||
| 202 | $userAddress | ||
| 203 | ->setZipCode($shippingAddress['postcode']) | ||
| 204 | ->setFullName($shippingAddress['first_name']." ".$shippingAddress['last_name']) | ||
| 205 | ->setCountryCode($shippingAddress['country']!='' ? strtoupper($shippingAddress['country']) : strtoupper($this->language)) | ||
| 206 | ->setCity($shippingAddress['city']) | ||
| 207 | ->setAddress($shippingAddress['address_1']." ".$shippingAddress['address_2']) | ||
| 208 | ->setDni($national_id) | ||
| 209 | ; | ||
| 210 | $orderShippingAddress = new Address(); | ||
| 211 | $orderShippingAddress | ||
| 212 | ->setZipCode($shippingAddress['postcode']) | ||
| 213 | ->setFullName($shippingAddress['first_name']." ".$shippingAddress['last_name']) | ||
| 214 | ->setCountryCode($shippingAddress['country']!='' ? strtoupper($shippingAddress['country']) : strtoupper($this->language)) | ||
| 215 | ->setCity($shippingAddress['city']) | ||
| 216 | ->setAddress($shippingAddress['address_1']." ".$shippingAddress['address_2']) | ||
| 217 | ->setFixPhone($phoneNumber) | ||
| 218 | ->setMobilePhone($phoneNumber) | ||
| 219 | ->setNationalId($national_id) | ||
| 220 | ->setDni($national_id) | ||
| 221 | ->setTaxId($tax_id) | ||
| 222 | ; | ||
| 223 | $orderBillingAddress = new Address(); | ||
| 224 | $orderBillingAddress | ||
| 225 | ->setZipCode($billingAddress['postcode']) | ||
| 226 | ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name']) | ||
| 227 | ->setCountryCode($billingAddress['country']!='' ? strtoupper($billingAddress['country']) : strtoupper($this->language)) | ||
| 228 | ->setCity($billingAddress['city']) | ||
| 229 | ->setAddress($billingAddress['address_1']." ".$billingAddress['address_2']) | ||
| 230 | ->setFixPhone($phoneNumber) | ||
| 231 | ->setMobilePhone($phoneNumber) | ||
| 232 | ->setNationalId($national_id) | ||
| 233 | ->setTaxId($tax_id) | ||
| 234 | ; | ||
| 235 | $orderUser = new User(); | ||
| 236 | $orderUser | ||
| 237 | ->setAddress($userAddress) | ||
| 238 | ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name']) | ||
| 239 | ->setBillingAddress($orderBillingAddress) | ||
| 240 | ->setEmail($billingAddress['email']) | ||
| 241 | ->setFixPhone($phoneNumber) | ||
| 242 | ->setMobilePhone($phoneNumber) | ||
| 243 | ->setShippingAddress($orderShippingAddress) | ||
| 244 | ->setNationalId($national_id) | ||
| 245 | ->setTaxId($tax_id) | ||
| 246 | ; | ||
| 247 | |||
| 248 |             if (!empty(maybeGetDateOfBirth($customer_id))) { | ||
| 249 | $orderUser->setDateOfBirth($birthday); | ||
| 250 | } | ||
| 251 | $previousOrders = getOrders($order->get_user(), $billingAddress['email']); | ||
| 252 |             foreach ($previousOrders as $previousOrder) { | ||
| 253 | $orderHistory = new OrderHistory(); | ||
| 254 | $orderElement = wc_get_order($previousOrder); | ||
| 255 | $orderCreated = $orderElement->get_date_created(); | ||
| 256 | $orderHistory | ||
| 257 | ->setAmount(intval(100 * $orderElement->get_total())) | ||
| 258 |                     ->setDate(new \DateTime($orderCreated->date('Y-m-d H:i:s'))) | ||
| 259 | ; | ||
| 260 | $orderUser->addOrderHistory($orderHistory); | ||
| 261 | } | ||
| 262 | |||
| 263 | $metadataOrder = new Metadata(); | ||
| 264 | $metadata = array( | ||
| 265 | 'pg_module' => 'woocommerce', | ||
| 266 | 'pg_version' => getModuleVersion(), | ||
| 267 | 'ec_module' => 'woocommerce', | ||
| 268 | 'ec_version' => WC()->version | ||
| 269 | ); | ||
| 270 | |||
| 271 |             foreach ($metadata as $key => $metadatum) { | ||
| 272 | $metadataOrder->addMetadata($key, $metadatum); | ||
| 273 | } | ||
| 274 | |||
| 275 | $details = new Details(); | ||
| 276 | $shippingCost = $order->shipping_total; | ||
| 277 | $details->setShippingCost(intval(strval(100 * $shippingCost))); | ||
| 278 | $items = $order->get_items(); | ||
| 279 | $promotedAmount = 0; | ||
| 280 |             foreach ($items as $key => $item) { | ||
| 281 | $wcProduct = $item->get_product(); | ||
| 282 | $product = new Product(); | ||
| 283 | $productDescription = sprintf( | ||
| 284 | '%s %s %s', | ||
| 285 | $wcProduct->get_name(), | ||
| 286 | $wcProduct->get_description(), | ||
| 287 | $wcProduct->get_short_description() | ||
| 288 | ); | ||
| 289 | $productDescription = substr($productDescription, 0, 9999); | ||
| 290 | |||
| 291 | $product | ||
| 292 | ->setAmount(intval(100 * ($item->get_total() + $item->get_total_tax()))) | ||
| 293 | ->setQuantity($item->get_quantity()) | ||
| 294 | ->setDescription($productDescription) | ||
| 295 | ; | ||
| 296 | $details->addProduct($product); | ||
| 297 | |||
| 298 | $promotedProduct = isProductPromoted($item->get_product_id()); | ||
| 299 |                 if ($promotedProduct == 'true') { | ||
| 300 | $promotedAmount+=$product->getAmount(); | ||
| 301 | $promotedMessage = 'Promoted Item: ' . $wcProduct->get_name() . | ||
| 302 | ' - Price: ' . $item->get_total() . | ||
| 303 | ' - Qty: ' . $product->getQuantity() . | ||
| 304 | ' - Item ID: ' . $item['id_product']; | ||
| 305 | $promotedMessage = substr($promotedMessage, 0, 999); | ||
| 306 |                     $metadataOrder->addMetadata('promotedProduct', $promotedMessage); | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | $orderShoppingCart = new ShoppingCart(); | ||
| 311 | $orderShoppingCart | ||
| 312 | ->setDetails($details) | ||
| 313 | ->setOrderReference($order->get_id()) | ||
| 314 | ->setPromotedAmount($promotedAmount) | ||
| 315 | ->setTotalAmount(intval(strval(100 * $order->total))) | ||
| 316 | ; | ||
| 317 | $orderConfigurationUrls = new Urls(); | ||
| 318 | $cancelUrl = $this->getKoUrl($order); | ||
| 319 |             $callback_arg = array('wc-api'=>'wcpagantisgateway', | ||
| 320 | 'key'=>$order->get_order_key(), | ||
| 321 | 'order-received'=>$order->get_id(), | ||
| 322 | 'origin' => '', | ||
| 323 | 'token' => $this->urlToken | ||
| 324 | ); | ||
| 325 | |||
| 326 | $callback_arg_user = $callback_arg; | ||
| 327 | $callback_arg_user['origin'] = 'redirect'; | ||
| 328 | $callback_arg_user['product'] = Ucfirst(WcPagantisGateway::METHOD_ID); | ||
| 329 |             $callback_url_user = add_query_arg($callback_arg_user, home_url('/')); | ||
| 330 | |||
| 331 | $callback_arg_notif = $callback_arg; | ||
| 332 | $callback_arg_notif['origin'] = 'notification'; | ||
| 333 | $callback_arg_notif['product'] = Ucfirst(WcPagantisGateway::METHOD_ID); | ||
| 334 |             $callback_url_notif = add_query_arg($callback_arg_notif, home_url('/')); | ||
| 335 | |||
| 336 | $orderConfigurationUrls | ||
| 337 | ->setCancel($cancelUrl) | ||
| 338 | ->setKo($callback_url_user) | ||
| 339 | ->setAuthorizedNotificationCallback($callback_url_notif) | ||
| 340 | ->setRejectedNotificationCallback(null) | ||
| 341 | ->setOk($callback_url_user) | ||
| 342 | ; | ||
| 343 | $orderChannel = new Channel(); | ||
| 344 | $orderChannel | ||
| 345 | ->setAssistedSale(false) | ||
| 346 | ->setType(Channel::ONLINE) | ||
| 347 | ; | ||
| 348 | |||
| 349 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); | ||
| 350 | $purchaseCountry = | ||
| 351 | in_array(strtolower($this->language), $allowedCountries) ? $this->language : | ||
| 352 | in_array(strtolower($shippingAddress['country']), $allowedCountries) ? $shippingAddress['country'] : | ||
| 353 | in_array(strtolower($billingAddress['country']), $allowedCountries) ? $billingAddress['country'] : null; | ||
| 354 | |||
| 355 | $orderConfiguration = new Configuration(); | ||
| 356 | $orderConfiguration | ||
| 357 | ->setChannel($orderChannel) | ||
| 358 | ->setUrls($orderConfigurationUrls) | ||
| 359 | ->setPurchaseCountry($purchaseCountry) | ||
| 360 | ; | ||
| 361 | |||
| 362 | $orderApiClient = new Order(); | ||
| 363 | $orderApiClient | ||
| 364 | ->setConfiguration($orderConfiguration) | ||
| 365 | ->setMetadata($metadataOrder) | ||
| 366 | ->setShoppingCart($orderShoppingCart) | ||
| 367 | ->setUser($orderUser) | ||
| 368 | ; | ||
| 369 | |||
| 370 |             if ($this->pagantis_public_key=='' || $this->pagantis_private_key=='') { | ||
| 371 |                 throw new \Exception('Public and Secret Key not found'); | ||
| 372 | } | ||
| 373 | $orderClient = new Client($this->pagantis_public_key, $this->pagantis_private_key); | ||
| 374 | $pagantisOrder = $orderClient->createOrder($orderApiClient); | ||
| 375 |             if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { | ||
| 376 | $url = $pagantisOrder->getActionUrls()->getForm(); | ||
| 377 | addOrderToProcessingQueue($pagantisOrder->getId(), $order->get_id(), $this->urlToken, self::METHOD_ID); | ||
| 378 |             } else { | ||
| 379 | throw new OrderNotFoundException(); | ||
| 380 | } | ||
| 381 | |||
| 382 |             if ($url=="") { | ||
| 383 |                 throw new Exception(_("No ha sido posible obtener una respuesta de Pagantis")); | ||
| 384 |             } elseif ($this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE']=='0') { | ||
| 385 | wp_redirect($url); | ||
| 386 | exit; | ||
| 387 |             } else { | ||
| 388 | $template_fields = array( | ||
| 389 | 'url' => $url, | ||
| 390 | 'checkoutUrl' => $cancelUrl | ||
| 391 | ); | ||
| 392 |                 wc_get_template('iframe.php', $template_fields, '', $this->template_path); | ||
| 393 | } | ||
| 394 |         } catch (\Exception $exception) { | ||
| 395 |             wc_add_notice(__('Payment error ', 'pagantis') . $exception->getMessage(), 'error'); | ||
| 396 | insertLogEntry($exception); | ||
| 397 |             $checkout_url = get_permalink(wc_get_page_id('checkout')); | ||
| 398 | wp_redirect($checkout_url); | ||
| 399 | exit; | ||
| 400 | } | ||
| 711 | 
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