| Conditions | 15 |
| Paths | 78 |
| Total Lines | 96 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 34 | public function postProcess() |
||
| 35 | { |
||
| 36 | $cart = $this->context->cart; |
||
| 37 | |||
| 38 | if ($cart->id_customer == 0 |
||
| 39 | || $cart->id_address_delivery == 0 |
||
| 40 | || $cart->id_address_invoice == 0 |
||
| 41 | || !$this->module->active |
||
| 42 | || empty($_REQUEST['b2binpay-crypto']) |
||
| 43 | ) { |
||
| 44 | Tools::redirect('index.php?controller=order&step=1'); |
||
| 45 | } |
||
| 46 | |||
| 47 | $authorized = false; |
||
| 48 | |||
| 49 | foreach (Module::getPaymentModules() as $module) { |
||
| 50 | if ($module['name'] == 'b2binpay') { |
||
| 51 | $authorized = true; |
||
| 52 | break; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | if (!$authorized) { |
||
| 57 | die($this->module->l('This payment method is not available.', 'redirect')); |
||
| 58 | } |
||
| 59 | |||
| 60 | $customer = new Customer($cart->id_customer); |
||
| 61 | |||
| 62 | if (!Validate::isLoadedObject($customer)) { |
||
| 63 | Tools::redirect('index.php?controller=order&step=1'); |
||
| 64 | } |
||
| 65 | |||
| 66 | $wallet_id = $_REQUEST['b2binpay-crypto']; |
||
| 67 | $wallet_list = json_decode(Configuration::get('B2BINPAY_WALLETS'), true); |
||
| 68 | |||
| 69 | $wallet = array_reduce( |
||
| 70 | $wallet_list, |
||
| 71 | function ($carry, $item) use ($wallet_id) { |
||
| 72 | if ($item['id'] === $wallet_id) { |
||
| 73 | $carry = $item; |
||
| 74 | } |
||
| 75 | |||
| 76 | return $carry; |
||
| 77 | }, |
||
| 78 | array() |
||
| 79 | ); |
||
| 80 | |||
| 81 | $currency = $this->context->currency; |
||
| 82 | $total = (string)$cart->getOrderTotal(true, Cart::BOTH); |
||
| 83 | |||
| 84 | $amount = $this->module->provider->convertCurrency( |
||
| 85 | (string)$total, |
||
| 86 | $currency->iso_code, |
||
| 87 | $wallet['alpha'] |
||
| 88 | ); |
||
| 89 | |||
| 90 | if (!empty(Configuration::get('B2BINPAY_MARKUP'))) { |
||
| 91 | $amount = $this->module->provider->addMarkup( |
||
| 92 | $amount, |
||
| 93 | $wallet['alpha'], |
||
| 94 | Configuration::get('B2BINPAY_MARKUP') |
||
| 95 | ); |
||
| 96 | } |
||
| 97 | |||
| 98 | try { |
||
| 99 | $bill = $this->module->provider->createBill( |
||
| 100 | $wallet['id'], |
||
| 101 | $amount, |
||
| 102 | $wallet['alpha'], |
||
| 103 | Configuration::get('B2BINPAY_LIFETIME'), |
||
| 104 | $cart->id, |
||
| 105 | $this->context->link->getModuleLink($this->module->name, 'callback', array(), true) |
||
| 106 | ); |
||
| 107 | } catch (B2BinpayException $e) { |
||
| 108 | die($this->module->l('Payment error: '.$e->getMessage(), 'redirect')); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (empty($bill) || empty($bill->url)) { |
||
| 112 | die($this->module->l('Payment gateway error.', 'redirect')); |
||
| 113 | } |
||
| 114 | |||
| 115 | $message = "B2BinPay created new invoice for $amount ETH. Bill ID: $bill->id"; |
||
| 116 | |||
| 117 | $this->module->validateOrder( |
||
| 118 | $cart->id, |
||
| 119 | Configuration::get('PS_OS_BANKWIRE'), |
||
| 120 | $total, |
||
| 121 | Configuration::get('B2BINPAY_TITLE'), |
||
| 122 | $message, |
||
| 123 | array(), |
||
| 124 | (int)$currency->id, |
||
| 125 | false, |
||
| 126 | $customer->secure_key |
||
| 127 | ); |
||
| 128 | |||
| 129 | Tools::redirect($bill->url); |
||
| 130 | } |
||
| 132 |
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