vindi/vindi-woocommerce

View on GitHub
src/includes/admin/Settings.php

Summary

Maintainability
A
2 hrs
Test Coverage

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

  function init_form_fields()
  {
    $url           = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));
    $logs_url      = '<a href="' . $url . '" target="_blank">' . __('Ver Logs', VINDI) . '</a>';
    $nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';
Severity: Major
Found in src/includes/admin/Settings.php - About 2 hrs to fix

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

        $sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    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 private fields such as '$plugin'.
    Open

      private $plugin;
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    UnusedPrivateField

    Since: 0.2

    Detects when a private field is declared and/or assigned a value, but not used.

    Example

    class Something
    {
        private static $FOO = 2; // Unused
        private $i = 5; // Unused
        private $j = 6;
        public function addOne()
        {
            return $this->j++;
        }
    }

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

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

        } else {
          return is_ssl();
        }
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

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

        } else {
          return 'processing';
        }
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

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

        } else {
          update_option('vindi_invalid_api_key', false);
          $this->invalidApiKey = false;
        }
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

    Source https://phpmd.org/rules/cleancode.html#elseexpression

    Visibility must be declared on method "init_form_fields"
    Open

      function init_form_fields()

    Visibility must be declared on method "__construct"
    Open

      function __construct()

    Visibility must be declared on method "checkKey"
    Open

      function checkKey()

    The 'get_is_active_sandbox()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

      public function get_is_active_sandbox()
      {
        return $this->settings['sandbox'];
      }
    Severity: Minor
    Found in src/includes/admin/Settings.php by phpmd

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    Line exceeds 120 characters; contains 126 characters
    Open

            'description'      => __('Ative esta opção para habilitar a comunicação com o ambiente Sandbox da Vindi.', VINDI),

    Line exceeds 120 characters; contains 166 characters
    Open

            'description'      => sprintf(__('Envia informações de RG e Inscrição Estadual para Emissão de NFe\'s com nossos parceiros. %s', VINDI), $nfe_know_more),

    Line exceeds 120 characters; contains 136 characters
    Open

        $prospects_url = '<a href="https://app.vindi.com.br/prospects/new" target="_blank">' . __('Não possui uma conta?', VINDI) . '</a>';

    Line exceeds 120 characters; contains 123 characters
    Open

        $url           = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));

    Line exceeds 120 characters; contains 159 characters
    Open

        $sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return sprintf('%s/index.php/wc-api/%s?token=%s',

    Line exceeds 120 characters; contains 128 characters
    Open

            'description'      => __('Status que o pedido deverá ter após receber a confirmação de pagamento da Vindi.', VINDI),

    Line exceeds 120 characters; contains 133 characters
    Open

            'description'      => sprintf(__('Ative esta opção para habilitar logs de depuração do servidor. %s', VINDI), $logs_url),

    Line exceeds 120 characters; contains 159 characters
    Open

        $nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function get_webhooks_url() {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      private $plugin;

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if (is_admin()) {

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

        $this->form_fields = array(

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

          ),

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

          ),

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

        global $woocommerce;

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

        $this->api = new VindiApi($this->get_api_key(), $this->logger, $this->get_is_active_sandbox());

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

          sprintf(

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

        $url           = admin_url(sprintf('admin.php?page=wc-status&tab=logs&log_file=%s-%s-log', VINDI, $this->get_token()));

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

        $this->init_settings();

    Expected 0 spaces before closing bracket; 1 found
    Open

        $this->invalidApiKey = get_option( 'vindi_invalid_api_key', false );

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      function __construct()

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

      {

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

        $this->routes = new VindiRoutes($this);

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

      {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

        $prospects_url = '<a href="https://app.vindi.com.br/prospects/new" target="_blank">' . __('Não possui uma conta?', VINDI) . '</a>';

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

        return $settings_tabs;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function settings_tab()

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

          '',

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

          'return_status'        => array(

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

          ),

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      private $invalidApiKey;

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

        $this->debug = $this->get_option('debug') == 'yes' ? true : false;

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

        $this->woocommerce = $woocommerce;

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

        $this->invalidApiKey = get_option( 'vindi_invalid_api_key', false );

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public static function add_settings_tab($settings_tabs)

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public $logger;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_template($name, $args = array())

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

      {

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

        $nfe_know_more = '<a href="http://atendimento.vindi.com.br/hc/pt-br/articles/204450944-Notas-fiscais" target="_blank">' . __('Saiba mais', VINDI) . '</a>';

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

        );

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public $woocommerce;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public $routes;

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

        $this->token = sanitize_file_name(wp_hash(VINDI));

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

        $sand_box_article = '<a href="https://atendimento.vindi.com.br/hc/pt-br/articles/115012242388-Sandbox" target="_blank">' . __('Dúvidas?', VINDI) . '</a>';

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

          $args,

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

          sprintf(

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

          )

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      function init_form_fields()

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      private $token;

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

          'send_nfe_information' => array(

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

          ),

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

          ),

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

      {

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

          'debug'                => array(

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

          $args,

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

          ),

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

        );

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

          'api_key'              => array(

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

          'testing'              => array(

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

        $this->logger = new VindiLogger(VINDI, $this->debug);

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

        $this->get_template('admin-settings.html.php', array('settings' => $this));

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

          $name,

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

          )

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

          'vindi_synchronism'        => array(

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

        return 'text';

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      private $debug;

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

      {

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

        $this->dependencies  = new VindiDependencies;

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

        $settings_tabs['settings_vindi'] = __('Vindi', VINDI);

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

          'shipping_and_tax_config'  => array(

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

          'sandbox'             => array(

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

          ),

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Expected 1 space after IF keyword; 0 found
    Open

        if(isset($this->settings['return_status'])) {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

        return 'yes' === $this->settings['send_nfe_information'];

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function is_api_key_valid()

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

    Opening brace should be on a new line
    Open

        public function get_webhooks_url() {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_token()

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

      {

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

          return;

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

          include_once VINDI_SRC . 'views/invalid-api-key.php';

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

          return 'processing';

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function send_nfe_information()

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

          return is_ssl();

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_return_status()

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public $dependencies;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public $api;

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

        $this->init_form_fields();

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

        return $this->settings['sandbox'];

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if (!$api_key) {

    Space after opening parenthesis of function call prohibited
    Open

        $this->invalidApiKey = get_option( 'vindi_invalid_api_key', false );

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

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

        wc_get_template(

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

          $name,

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

          '',

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

        $logs_url      = '<a href="' . $url . '" target="_blank">' . __('Ver Logs', VINDI) . '</a>';

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

          ),

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      function checkKey()

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

        return $this->settings['api_key'];

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        } else {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function api_key_field()

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

      {

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

        $api_key = $this->get_api_key();

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

        $this->api = new VindiApi($api_key, $this->logger, $this->get_is_active_sandbox());

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_is_active_sandbox()

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

          update_option('vindi_invalid_api_key', true);

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if($this->invalidApiKey) {

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

          include_once VINDI_SRC . 'views/invalid-api-key.php';

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if(isset($this->settings['return_status'])) {

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

      {

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

      {

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

      {

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

      {

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

      {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

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

          update_option('vindi_invalid_api_key', false);

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        }

    Opening parenthesis of a multi-line function call must be the last content on the line
    Open

            return sprintf('%s/index.php/wc-api/%s?token=%s',

    Closing brace indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

        return 'yes' === $this->settings['vindi_synchronism'];

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if ('unauthorized' === $this->api->test_api_key($api_key)) {

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

          $this->invalidApiKey = true;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        if ($this->get_is_active_sandbox()) {

    Expected 1 space after IF keyword; 0 found
    Open

        if($this->invalidApiKey) {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      }

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

      {

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

        );

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

        );

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_synchronism_status()

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

      {

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_api_key()

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

          return true;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function get_shipping_and_tax_config()

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

        return 'yes' === $this->settings['shipping_and_tax_config'];

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

          return $this->settings['return_status'];

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

        return $this->token;

    Line indented incorrectly; expected 4 spaces, found 2
    Open

      public function check_ssl()

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

      {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        } else {

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

          $this->invalidApiKey = false;

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

      {

    Line indented incorrectly; expected 8 spaces, found 4
    Open

        } else {

    There are no issues that match your filters.

    Category
    Status