felixarntz/wpdlib

View on GitHub
inc/WPDLib/FieldTypes/Number.php

Summary

Maintainability
C
7 hrs
Test Coverage

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

        public function validate( $val = null ) {
            $format = 'float';
            $zero = 0.0;
            if ( is_int( $this->args['step'] ) ) {
                $format = 'int';
Severity: Minor
Found in inc/WPDLib/FieldTypes/Number.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 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function validate( $val = null ) {
            $format = 'float';
            $zero = 0.0;
            if ( is_int( $this->args['step'] ) ) {
                $format = 'int';
Severity: Minor
Found in inc/WPDLib/FieldTypes/Number.php - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

                    return new WPError( 'invalid_number_step', sprintf( __( 'The number %1$s is invalid since it is not divisible by %2$s.', 'wpdlib' ), FieldManager::format( $val, $format, 'output' ), FieldManager::format( $this->args['step'], $format, 'output' ) ) );
    Severity: Major
    Found in inc/WPDLib/FieldTypes/Number.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return new WPError( 'invalid_number_too_small', sprintf( __( 'The number %1$s is invalid. It must be greater than or equal to %2$s.', 'wpdlib' ), FieldManager::format( $val, $format, 'output' ), FieldManager::format( $this->args['min'], $format, 'output' ) ) );
      Severity: Major
      Found in inc/WPDLib/FieldTypes/Number.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return $val;
        Severity: Major
        Found in inc/WPDLib/FieldTypes/Number.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return new WPError( 'invalid_number_too_big', sprintf( __( 'The number %1$s is invalid. It must be lower than or equal to %2$s.', 'wpdlib' ), FieldManager::format( $val, $format, 'output' ), FieldManager::format( $this->args['max'], $format, 'output' ) ) );
          Severity: Major
          Found in inc/WPDLib/FieldTypes/Number.php - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status