felixarntz/wp-site-identity

View on GitHub
src/settings/class-wp-site-identity-setting-validator.php

Summary

Maintainability
C
7 hrs
Test Coverage

Function validate_string_value has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    protected function validate_string_value( $value, $args ) {
        $value = trim( (string) $value );

        if ( ! empty( $args['enum'] ) && ! in_array( $value, $args['enum'], true ) ) {
            /* translators: 1: value, 2: list of valid values */
Severity: Minor
Found in src/settings/class-wp-site-identity-setting-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

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

    protected function validate_numeric_value( $value, $args ) {
        if ( ! is_numeric( $value ) ) {
            /* translators: 1: value, 2: type name */
            throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, $args['type'] ) );
        }
Severity: Minor
Found in src/settings/class-wp-site-identity-setting-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

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

    protected function validate_object_value( $value, $args ) {
        if ( $value instanceof stdClass ) {
            $value = (array) $value;
        }

Severity: Minor
Found in src/settings/class-wp-site-identity-setting-validator.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

Avoid too many return statements within this method.
Open

        return $value;
Severity: Major
Found in src/settings/class-wp-site-identity-setting-validator.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

                    return $this->validate_string_value( $value, $args );
    Severity: Major
    Found in src/settings/class-wp-site-identity-setting-validator.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return $this->validate_numeric_value( $value, $args );
      Severity: Major
      Found in src/settings/class-wp-site-identity-setting-validator.php - About 30 mins to fix

        The method validate_numeric_value() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
        Open

            protected function validate_numeric_value( $value, $args ) {
                if ( ! is_numeric( $value ) ) {
                    /* translators: 1: value, 2: type name */
                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, $args['type'] ) );
                }

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

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

        The method validate_string_value() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
        Open

            protected function validate_string_value( $value, $args ) {
                $value = trim( (string) $value );
        
                if ( ! empty( $args['enum'] ) && ! in_array( $value, $args['enum'], true ) ) {
                    /* translators: 1: value, 2: list of valid values */

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

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

        Missing class import via use statement (line '108', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, 'array' ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '222', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not one of %2$s.', 'wp-site-identity' ), $value, implode( ', ', $args['enum'] ) ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '230', column '17').
        Open

                                throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%s is not a valid date.', 'wp-site-identity' ), $value ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '236', column '17').
        Open

                                throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%s is not a valid email address.', 'wp-site-identity' ), $value ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '34', column '15').
        Open

                        throw new WP_Site_Identity_Setting_Validation_Error_Exception( $validated_value->get_error_message() );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '138', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, 'object' ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '242', column '17').
        Open

                                throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%s is not a valid IP address.', 'wp-site-identity' ), $value ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '195', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s must be greater than or equal to %2$s.', 'wp-site-identity' ), $value, number_format_i18n( $args['minimum'] ) ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '185', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, $args['type'] ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '190', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, 'integer' ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '165', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s is not of type %2$s.', 'wp-site-identity' ), $value, 'boolean' ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '200', column '14').
        Open

                    throw new WP_Site_Identity_Setting_Validation_Error_Exception( sprintf( __( '%1$s must be less than or equal to %2$s.', 'wp-site-identity' ), $value, number_format_i18n( $args['maximum'] ) ) );

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            protected function validate_value( $value, $args ) {
                if ( empty( $args['type'] ) ) {
                    return $value;
                }
        
        
        Severity: Major
        Found in src/settings/class-wp-site-identity-setting-validator.php and 1 other location - About 1 hr to fix
        src/settings/class-wp-site-identity-setting-sanitizer.php on lines 67..87

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 118.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function validate( $value, WP_Site_Identity_Setting $setting ) {
                $validate_callback = $setting->get_validate_callback();
        
                if ( isset( $validate_callback ) ) {
                    $validated_value = call_user_func( $validate_callback, $value, $setting );
        Severity: Minor
        Found in src/settings/class-wp-site-identity-setting-validator.php and 1 other location - About 55 mins to fix
        src/settings/class-wp-site-identity-setting-sanitizer.php on lines 27..41

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 98.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status