wikimedia/mediawiki-extensions-DonationInterface

View on GitHub
gateway_common/DataValidator.php

Summary

Maintainability
D
2 days
Test Coverage

File DataValidator.php has 372 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use SmashPig\Core\ValidationError;

/**
Severity: Minor
Found in gateway_common/DataValidator.php - About 4 hrs to fix

    Function validate has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function validate( GatewayType $gateway, $data, $check_not_empty = [] ) {
            // return the array of errors that should be generated on validate.
            // just the same way you'd do it if you were a form passing the error array around.
    
            /**
    Severity: Minor
    Found in gateway_common/DataValidator.php - About 3 hrs 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

    Method validate has 78 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function validate( GatewayType $gateway, $data, $check_not_empty = [] ) {
            // return the array of errors that should be generated on validate.
            // just the same way you'd do it if you were a form passing the error array around.
    
            /**
    Severity: Major
    Found in gateway_common/DataValidator.php - About 3 hrs to fix

      DataValidator has 26 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class DataValidator {
      
          /**
           * getErrorToken, intended to be used by classes that exist relatively close
           * to the form classes, returns the error token (defined on the forms) that
      Severity: Minor
      Found in gateway_common/DataValidator.php - About 3 hrs to fix

        Method cc_number_exists_in_str has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function cc_number_exists_in_str( string $str ): bool {
                $luhnRegex = <<<EOT
        /
        (?#amex)(3[47][0-9]{13})|
        (?#bankcard)(5610[0-9]{12})|(56022[1-5][0-9]{10})|
        Severity: Minor
        Found in gateway_common/DataValidator.php - About 1 hr to fix

          Function value_appears_in has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function value_appears_in( $needle, $haystack ) {
                  $needle = ( is_array( $needle ) ) ? $needle : [ $needle ];
                  $haystack = ( is_array( $haystack ) ) ? $haystack : [ $haystack ];
          
                  $plusCheck = array_key_exists( '+', $haystack );
          Severity: Minor
          Found in gateway_common/DataValidator.php - About 55 mins 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

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

              public static function luhn_check( $str ) {
                  $odd = ( strlen( $str ) % 2 );
                  $sum = 0;
                  $len = strlen( $str );
          
          
          Severity: Minor
          Found in gateway_common/DataValidator.php - About 45 mins 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

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

              protected static function checkValidationPassed( $fields, $results ) {
                  foreach ( $fields as $field ) {
                      foreach ( $results as $phase => $results_fields ) {
                          if ( array_key_exists( $field, $results_fields )
                              && $results_fields[$field] !== true
          Severity: Minor
          Found in gateway_common/DataValidator.php - About 35 mins 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 too many return statements within this method.
          Open

                      return true;
          Severity: Major
          Found in gateway_common/DataValidator.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return !is_array( $value );
            Severity: Major
            Found in gateway_common/DataValidator.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return (bool)$result;
              Severity: Major
              Found in gateway_common/DataValidator.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return false;
                Severity: Major
                Found in gateway_common/DataValidator.php - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status