vindi/vindi-woocommerce

View on GitHub
src/utils/PaymentProcessor.php

Summary

Maintainability
F
5 days
Test Coverage

Showing 64 of 64 total issues

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

installments accesses the super-global variable $_POST.
Open

protected function installments()
{
if (
'credit_card' == $this->payment_method_code() &&
isset($_POST['vindi_cc_installments'])
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

installments accesses the super-global variable $_POST.
Open

protected function installments()
{
if (
'credit_card' == $this->payment_method_code() &&
isset($_POST['vindi_cc_installments'])
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

get_cc_payment_type accesses the super-global variable $_POST.
Open

public function get_cc_payment_type($customer_id)
{
if ($this->gateway->verify_user_payment_profile()) {
return false;
}
Severity: Minor
Found in src/utils/PaymentProcessor.php by phpmd

File PaymentProcessor.php has 1056 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
 
namespace VindiPaymentGateways;
 
use DateTime;
Severity: Major
Found in src/utils/PaymentProcessor.php - About 2 days to fix

    VindiPaymentProcessor has 69 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class VindiPaymentProcessor
    {
    /**
    * Order type is invalid.
    */
    Severity: Major
    Found in src/utils/PaymentProcessor.php - About 1 day to fix

      The class VindiPaymentProcessor has 52 non-getter- and setter-methods. Consider refactoring VindiPaymentProcessor to keep number of methods under 25.
      Open

      class VindiPaymentProcessor
      {
      /**
      * Order type is invalid.
      */
      Severity: Minor
      Found in src/utils/PaymentProcessor.php by phpmd

      The class VindiPaymentProcessor has an overall complexity of 250 which is very high. The configured complexity threshold is 50.
      Open

      class VindiPaymentProcessor
      {
      /**
      * Order type is invalid.
      */
      Severity: Minor
      Found in src/utils/PaymentProcessor.php by phpmd

      Method process_order has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      public function process_order()
      {
      $subscription_id = $this->order->get_meta('vindi_subscription_id');
      $subscription_exists = $this->exist_subscription($subscription_id);
      if ($subscription_exists) {
      Severity: Major
      Found in src/utils/PaymentProcessor.php - About 2 hrs to fix

        Function process_order has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        public function process_order()
        {
        $subscription_id = $this->order->get_meta('vindi_subscription_id');
        $subscription_exists = $this->exist_subscription($subscription_id);
        if ($subscription_exists) {
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 2 hrs to fix

        Function build_tax_item has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

        protected function build_tax_item($order_items)
        {
         
        $total_tax = 0;
        $taxItem = [];
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 1 hr to fix

        Function order_has_trial_and_simple_product has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        public function order_has_trial_and_simple_product()
        {
        $has_trial = false;
        $has_simple_product = false;
        $order_items = $this->order->get_items();
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 1 hr to fix

        Function get_cycle_from_product_type has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        private function get_cycle_from_product_type($item)
        {
        $cycles = null;
        $product = is_object($item) && method_exists($item, 'get_product') ? $item->get_product() : false;
         
         
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 45 mins to fix

        Function build_sign_up_fee_item has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        protected function build_sign_up_fee_item($order_items)
        {
        foreach ($order_items as $order_item) {
        if (!is_object($order_item) || !method_exists($order_item, 'get_product')) {
        continue;
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 45 mins to fix

        Function build_shipping_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        protected function build_shipping_item($order_items)
        {
        $shipping_item = [];
        $shipping_method = $this->order->get_shipping_method();
        $get_total_shipping = $this->order->get_shipping_total();
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 35 mins to fix

        Function build_product_items_for_subscription has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        protected function build_product_items_for_subscription($order_item)
        {
        $plan_cycles = $this->get_cycle_from_product_type($order_item);
        $product_item = array(
        'product_id' => $order_item['vindi_id'],
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 35 mins to fix

        Function get_product has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        protected function get_product($order_item)
        {
         
        $product = $order_item->get_product();
        $product_id = $order_item->get_id();
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 35 mins to fix

        Function get_plan_from_order_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        public function get_plan_from_order_item($order_item)
        {
        $product = $order_item->get_product();
         
        if (isset($order_item['variation_id']) && $order_item['variation_id'] != 0) {
        Severity: Minor
        Found in src/utils/PaymentProcessor.php - About 35 mins to fix

        Avoid too many return statements within this method.
        Open

        return $cycles > 0 ? $cycles : null;
        Severity: Major
        Found in src/utils/PaymentProcessor.php - About 30 mins to fix

          Function coupon_supports_product has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

          protected function coupon_supports_product($order_item, $coupon)
          {
          $product_id = $order_item->get_product()->get_id();
          $included_products = $coupon->get_product_ids();
          $excluded_products = $coupon->get_excluded_product_ids();
          Severity: Minor
          Found in src/utils/PaymentProcessor.php - About 25 mins to fix

          The class VindiPaymentProcessor has 1608 lines of code. Current threshold is 1000. Avoid really long classes.
          Open

          class VindiPaymentProcessor
          {
          /**
          * Order type is invalid.
          */
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method process_order() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
          Open

          public function process_order()
          {
          $subscription_id = $this->order->get_meta('vindi_subscription_id');
          $subscription_exists = $this->exist_subscription($subscription_id);
          if ($subscription_exists) {
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method get_cycle_from_product_type() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
          Open

          private function get_cycle_from_product_type($item)
          {
          $cycles = null;
          $product = is_object($item) && method_exists($item, 'get_product') ? $item->get_product() : false;
           
           
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method abort has a boolean flag argument $throw_exception, which is a certain sign of a Single Responsibility Principle violation.
          Open

          public function abort($message, $throw_exception = false)
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method add_additional_items uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $order_items[] = $this->build_product_from_order_item($order_type, $product);
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method order_has_trial_and_simple_product uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $has_simple_product = true;
          if ($has_trial) {
          return true;
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method build_product_from_order_item uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $order_items['price'] = (float) $order_items['subtotal'] / $order_items['qty'];
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid using static access to class 'VindiPaymentGateways\VindiHelpers' in method 'get_trial_matching_subscription_item'.
          Open

          $subscription = VindiHelpers::get_matching_subscription($this->order, $order_item);
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method get_plan_from_order_item uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $vindi_plan = get_post_meta($product->get_id(), 'vindi_plan_id', true);
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid using static access to class 'VindiPaymentGateways\VindiHelpers' in method 'build_shipping_item'.
          Open

          $wc_subscription = VindiHelpers::get_matching_subscription($this->order, $order_item);
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method get_product uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $vindi_product = $this->controllers->plans->create($product_id, '', '', true);
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method build_tax_item uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          $total_tax += (float) ($order_item->get_total_tax());
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid using static access to class 'VindiPaymentGateways\VindiHelpers' in method 'get_trial_matching_subscription_item'.
          Open

          $matching_item = VindiHelpers::get_matching_subscription_item($subscription, $order_item);
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The method build_tax_item uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
          Open

          } else {
          !empty($order_item['type']) && $total_tax += ($order_item['type'] === 'shipping' ? (float) $this->order->get_shipping_tax() : (float) $order_item->get_total_tax());
          }
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid using static access to class '\WC_Subscriptions_Product' in method 'subscription_has_trial'.
          Open

          return $this->is_subscription_type($product) && class_exists('WC_Subscriptions_Product') && WC_Subscriptions_Product::get_trial_length($product->get_id()) > 0;
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid unused local variables such as '$orderType'.
          Open

          switch ($orderType = $this->get_order_type()) {
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid unused local variables such as '$index'.
          Open

          foreach ($cart->get_fees() as $index => $fee) {
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Avoid unused parameters such as '$order_items'.
          Open

          protected function build_interest_rate_item($order_items)
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The property $vindi_settings is not named in camelCase.
          Open

          class VindiPaymentProcessor
          {
          /**
          * Order type is invalid.
          */
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          The property $single_freight is not named in camelCase.
          Open

          class VindiPaymentProcessor
          {
          /**
          * Order type is invalid.
          */
          Severity: Minor
          Found in src/utils/PaymentProcessor.php by phpmd

          Blank line found at start of control structure
          Open

          if ($sign_up_fee != null && $sign_up_fee > 0) {

          The DEFAULT body must start on the line following the statement
          Open

          default:

          The CASE body must start on the line following the statement
          Open

          case static::ORDER_TYPE_SUBSCRIPTION:

          Line exceeds 120 characters; contains 130 characters
          Open

          $this->abort(__('Falha ao registrar o método de pagamento. Verifique os dados e tente novamente.', VINDI), true);

          Inline control structures are not allowed
          Open

          if ($product->id === null) $product->id = 63;

          Line exceeds 120 characters; contains 140 characters
          Open

          public function __construct(WC_Order $order, VindiPaymentGateway $gateway, VindiSettings $vindi_settings, VindiControllers $controllers)

          Line exceeds 120 characters; contains 180 characters
          Open

          !empty($order_item['type']) && $total_tax += ($order_item['type'] === 'shipping' ? (float) $this->order->get_shipping_tax() : (float) $order_item->get_total_tax());

          Line exceeds 120 characters; contains 182 characters
          Open

          'card_expiration' => filter_var($_POST['vindi_cc_monthexpiry'], FILTER_SANITIZE_NUMBER_INT) . '/' . filter_var($_POST['vindi_cc_yearexpiry'], FILTER_SANITIZE_NUMBER_INT),

          Line exceeds 120 characters; contains 145 characters
          Open

          return $this->abort(__('Falha ao processar carrinho de compras. Verifique os itens escolhidos e tente novamente.', VINDI), true);

          Line exceeds 120 characters; contains 128 characters
          Open

          if (function_exists('wcs_order_contains_subscription') && wcs_order_contains_subscription($this->order, array('any'))) {

          Line exceeds 120 characters; contains 169 characters
          Open

          * @param WC_Order_Item_Product|WC_Order_Item_Product[] $product The product to be built. If the order type is 'bill' this will be an array of WC_Order_Item_Product,

          Line exceeds 120 characters; contains 149 characters
          Open

          return $this->abort(__('Falha ao recuperar informações sobre o produto na Vindi. Verifique os dados e tente novamente.', VINDI), true);

          Line exceeds 120 characters; contains 121 characters
          Open

          * @param WC_Order_Item_Product|WC_Order_Item_Product[] $order_items. Subscriptions will pass only one order_item and

          Line exceeds 120 characters; contains 126 characters
          Open

          $this->abort(__('Falha ao registrar o método de pagamento. Verifique os dados e tente novamente.', VINDI), true);

          Line exceeds 120 characters; contains 167 characters
          Open

          return $this->is_subscription_type($product) && class_exists('WC_Subscriptions_Product') && WC_Subscriptions_Product::get_trial_length($product->get_id()) > 0;

          Inline control structures are not allowed
          Open

          if (empty($subscription_order_item))

          Line exceeds 120 characters; contains 122 characters
          Open

          'tax' == $order_item['type'] || 'interest_rate' == $order_item['type'] || 'sign_up_fee' == $order_item['type']

          Expected 0 spaces after opening bracket; newline found
          Open

          if (

          Expected 0 spaces after opening bracket; newline found
          Open

          if (

          Expected 0 spaces after opening bracket; newline found
          Open

          if (
          Category
          Status