vindi/vindi-woocommerce

View on GitHub

Showing 2,474 of 2,474 total issues

Avoid using static access to class 'VindiPaymentGateways\VindiConversions' in method 'create'.
Open

    $plan_interval = VindiConversions::convert_interval($interval_count, $interval_type);
Severity: Minor
Found in src/controllers/PlansController.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

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

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

              } else {
                  $sortable_array[$k] = $v;
              }
Severity: Minor
Found in src/services/VindiHelpers.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 create uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

    } else {
      set_transient('vindi_product_message', 'error', 60);
    }
Severity: Minor
Found in src/controllers/PlansController.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 update() has an NPath complexity of 3538944. The configured NPath complexity threshold is 200.
Open

  function update($user_id, $order = null)
  {
    $vindi_customer_id = get_user_meta($user_id, 'vindi_customer_id', true);
    // Check meta Vindi ID
    if (empty($vindi_customer_id)) {

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

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

        if (empty(VindiHelpers::sanitize_xss($_POST['woocommerce_meta_nonce'])) ||
Severity: Minor
Found in src/includes/admin/CouponsMetaBox.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

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

        } else {
          set_transient('vindi_product_message', 'error', 60);
        }
Severity: Minor
Found in src/controllers/ProductController.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

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

Avoid assigning values to variables in if clauses and the like (line '440', column '20').
Open

  public function getMerchant($is_config = false)
  {
    if (false === ($merchant = get_transient('vindi_merchant')) || $is_config) {
      $response = $this->api->request('merchant', 'GET');

Severity: Minor
Found in src/routes/RoutesApi.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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

    } else {
      set_transient('vindi_product_message', 'error', 60);
    }
Severity: Minor
Found in src/controllers/PlansController.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

Avoid assigning values to variables in if clauses and the like (line '212', column '10').
Open

  public function createSubscription($data)
  {
    if (($response = $this->api->request('subscriptions', 'POST', $data)) &&
      isset($response['subscription']['id'])) {

Severity: Minor
Found in src/routes/RoutesApi.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

Avoid assigning values to variables in if clauses and the like (line '263', column '7').
Open

    public function getSubscription($subscription_id)
    {
        if ($response = $this->api->request("subscriptions/". filter_var($subscription_id, FILTER_SANITIZE_NUMBER_INT),'GET')['subscription'])
            return $response;

Severity: Minor
Found in src/routes/RoutesApi.php by phpmd

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

The method handle() contains an exit expression.
Open

            die('invalid access token');
Severity: Minor
Found in src/services/Webhooks.php by phpmd

ExitExpression

Since: 0.2

An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

Example

class Foo {
    public function bar($param)  {
        if ($param === 42) {
            exit(23);
        }
    }
}

Source https://phpmd.org/rules/design.html#exitexpression

Avoid using static access to class 'VindiPaymentGateways\VindiConversions' in method 'update'.
Open

        $plan_interval     = VindiConversions::convert_interval($interval_count, $interval_type);
Severity: Minor
Found in src/controllers/PlansController.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

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

The method create() has 204 lines of code. Current threshold is set to 100. Avoid really long methods.
Open

  function create($post_id, $post, $update, $recreated = false)
  {

    // Check if the post is a draft
    if (strpos(get_post_status($post_id), 'draft') !== false) {
Severity: Minor
Found in src/controllers/PlansController.php by phpmd

Avoid using static access to class 'VindiPaymentGateways\VindiConversions' in method 'create'.
Open

    $trigger_day = VindiConversions::convertTriggerToDay(
      $product->get_meta('_subscription_trial_length'),
      $product->get_meta('_subscription_trial_period')
    );
Severity: Minor
Found in src/controllers/PlansController.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

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

Avoid unused private fields such as '$recentRequest'.
Open

  private $recentRequest;
Severity: Minor
Found in src/services/Api.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

Severity
Category
Status
Source
Language