vindi/vindi-woocommerce

View on GitHub
src/includes/gateways/CreditPayment.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method init_form_fields has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function init_form_fields()
    {

      $this->form_fields = array(
        'enabled' => array(
Severity: Major
Found in src/includes/gateways/CreditPayment.php - About 2 hrs to fix

    Method __construct has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function __construct(VindiSettings $vindi_settings, VindiControllers $controllers)
        {
    
          global $woocommerce;
    
    
    Severity: Minor
    Found in src/includes/gateways/CreditPayment.php - About 1 hr to fix

      Function get_installments has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function get_installments()
          {
            if ($this->is_single_order())
              return $this->installments;
      
      
      Severity: Minor
      Found in src/includes/gateways/CreditPayment.php - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

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

            global $woocommerce;

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

              foreach ($cart->get_fees() as $index => $fee) {

      UnusedLocalVariable

      Since: 0.2

      Detects when a local variable is declared and/or assigned, but not used.

      Example

      class Foo {
          public function doSomething()
          {
              $i = 5; // Unused
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

      The property $enable_interest_rate is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $max_installments is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $interest_rate is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $vindi_settings is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $verify_method is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      The property $smallest_installment is not named in camelCase.
      Open

      class VindiCreditGateway extends VindiPaymentGateway
      {
          /**
           * @var VindiSettings
           */

      CamelCasePropertyName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name attributes.

      Example

      class ClassName {
          protected $property_name;
      }

      Source

      A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 20 and the first side effect is on line 8.
      Open

      <?php

      Inline control structures are not allowed
      Open

            if ($this->is_single_order())

      Line exceeds 120 characters; contains 132 characters
      Open

                'description' => __('Número máximo de parcelas para vendas avulsas. Deixe em 1x para desativar o parcelamento.', VINDI),

      Line exceeds 120 characters; contains 125 characters
      Open

                $user_payment_profile['card_number']     = sprintf('**** **** **** %s', $payment_profile['card_number_last_four']);

      Inline control structures are not allowed
      Open

            if ($installments != 0)

      Line exceeds 120 characters; contains 167 characters
      Open

                'description' => __(' Realiza a transação de verificação em todos os novos pedidos. (Taxas adicionais por verificação poderão ser cobradas).', VINDI),

      Inline control structures are not allowed
      Open

            else

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->form_fields = array(

      Line indented incorrectly; expected 8 spaces, found 6
      Open

            }

      Line indented incorrectly; expected at least 20 spaces, found 12
      Open

                  $installments = $plan['installments'];

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->has_fields           = true;

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            parent::__construct($vindi_settings, $controllers);

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            );

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $installments = 0;

      Line indented incorrectly; expected 16 spaces, found 10
      Open

                }

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->supports             = array(

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->init_form_fields();

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->enable_interest_rate = $this->get_option('enable_interest_rate');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->vindi_settings->get_template('creditcard-checkout.html.php', compact(

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return 1 === $old_payment_profile;

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              $order_max_times = floor($order_total / $this->smallest_installment);

      Line indented incorrectly; expected 8 spaces, found 6
      Open

            foreach ($this->vindi_settings->woocommerce->cart->cart_contents as $item) {

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            if ($installments != 0)

      Expected 1 space after ELSE keyword; newline found
      Open

            else

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            );

      Line indented incorrectly; expected 12 spaces, found 8
      Open

              }

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            );

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            global $woocommerce;

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                return;

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              return min($this->max_installments, $max_times, $this->get_installments());

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                $user_payment_profile['payment_company'] = $payment_profile['payment_company']['code'];

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                $user_payment_profile['card_number']     = sprintf('**** **** **** %s', $payment_profile['card_number_last_four']);

      Line indented incorrectly; expected at least 20 spaces, found 12
      Open

                  $installments = $plan['installments'];

      Multi-line function call not indented correctly; expected 10 spaces but found 8
      Open

              'vindi-old-cc-data-check',

      Multi-line function call not indented correctly; expected 10 spaces but found 8
      Open

              FILTER_SANITIZE_NUMBER_INT

      Line indented incorrectly; expected at least 16 spaces, found 10
      Open

                $plan = $this->routes->getPlan($plan_id);

      Line indented incorrectly; expected 8 spaces, found 6
      Open

            }

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

        exit;

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->id                   = 'vindi-credit-card';

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->init_settings();

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              $plan_id = $item['data']->get_meta('vindi_plan_id');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->method_title         = __('Vindi - Cartão de Crédito', VINDI);

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->method_description   = __('Aceitar pagamentos via cartão de crédito utilizando a Vindi.', VINDI);

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            ));

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return 'yes' === $this->verify_method;

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                $payment_profile = $this->routes->getPaymentProfile($user_vindi_id);

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                return $user_payment_profile;

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            if ($this->is_single_order())

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->icon                 = apply_filters('vindi_woocommerce_credit_card_icon', '');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->installments = $this->get_option('installments');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->interest_rate = $this->get_option('interest_rate');

      Line indented incorrectly; expected 12 spaces, found 8
      Open

              if (!empty($plan_id)) {

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              $max_times = empty($order_max_times) ? 1 : $order_max_times;

      Line indented incorrectly; expected at least 12 spaces, found 10
      Open

                $user_payment_profile['holder_name']     = $payment_profile['holder_name'];

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->smallest_installment = $this->get_option('smallest_installment');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $this->verify_method = $this->get_option('verify_method');

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return 'cc';

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return floatval($this->interest_rate);

      Multi-line function call not indented correctly; expected 10 spaces but found 8
      Open

              INPUT_POST,

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return 'yes' === $this->enable_interest_rate;

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            return $this->get_installments();

      Line indented incorrectly; expected 16 spaces, found 10
      Open

                } elseif ($plan['installments'] < $installments) {

      Line indented incorrectly; expected 8 spaces, found 6
      Open

            else

      Line indented incorrectly; expected at least 8 spaces, found 6
      Open

            $old_payment_profile = (int) filter_input(

      Line indented incorrectly; expected 8 spaces, found 6
      Open

            if ($this->is_single_order()) {

      Line indented incorrectly; expected 16 spaces, found 10
      Open

                if ($installments == 0) {

      There are no issues that match your filters.

      Category
      Status