gocodebox/lifterlms

View on GitHub
includes/forms/class-llms-form-validator.php

Summary

Maintainability
C
7 hrs
Test Coverage
A
100%

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

    public function validate_matching_fields( $posted_data, $fields ) {

        $err      = new WP_Error();
        $err_data = array();

Severity: Minor
Found in includes/forms/class-llms-form-validator.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

Method validate_field has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function validate_field( $posted_value, $field ) {

        // Validate field by type.
        $type_map = array(
            'email'  => array( $this, 'validate_field_email' ),
Severity: Minor
Found in includes/forms/class-llms-form-validator.php - About 1 hr to fix

    Method validate_matching_fields has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function validate_matching_fields( $posted_data, $fields ) {
    
            $err      = new WP_Error();
            $err_data = array();
    
    
    Severity: Minor
    Found in includes/forms/class-llms-form-validator.php - About 1 hr to fix

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

          public function validate_fields( $posted_data, $fields ) {
      
              if ( empty( $posted_data ) && ! empty( $fields ) ) {
                  return new WP_Error( 'llms-form-no-input', __( 'Cannot validate a form with no user input.', 'lifterlms' ) );
              }
      Severity: Minor
      Found in includes/forms/class-llms-form-validator.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

      Consider simplifying this complex logical expression.
      Open

                  if ( ( ! empty( $field['attributes']['min'] ) || ( isset( $field['attributes']['min'] ) && '0' === $field['attributes']['min'] ) ) && $temp_value < $field['attributes']['min'] ) {
                      // Translators: %1$s = field label or name; %2$s = user submitted value; %3$d = minimum allowed number.
                      return new WP_Error( 'llms-form-field-invalid', sprintf( __( 'The %1$s "%2$s" must be greater than or equal to %3$d.', 'lifterlms' ), isset( $field['label'] ) ? $field['label'] : $field['name'], $posted_value, $field['attributes']['min'] ) );
                  } elseif ( ( ! empty( $field['attributes']['max'] ) || ( isset( $field['attributes']['max'] ) && '0' === $field['attributes']['max'] ) ) && $temp_value > $field['attributes']['max'] ) {
                      // Translators: %1$s = field label or name; %2$s = user submitted value; %3$d = maximum allowed number.
      Severity: Major
      Found in includes/forms/class-llms-form-validator.php - About 1 hr to fix

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

            protected function validate_field_number( $posted_value, $field ) {
        
                $temp_value = str_replace( ',', '', $posted_value );
                if ( ! is_numeric( $temp_value ) ) {
                    // Translators: %1$s field label or name; %2$s = user submitted value.
        Severity: Minor
        Found in includes/forms/class-llms-form-validator.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 validate_field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public function validate_field( $posted_value, $field ) {
        
                // Validate field by type.
                $type_map = array(
                    'email'  => array( $this, 'validate_field_email' ),
        Severity: Minor
        Found in includes/forms/class-llms-form-validator.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

        There are no issues that match your filters.

        Category
        Status