swaggest/php-json-schema

View on GitHub
src/Constraint/Format.php

Summary

Maintainability
C
1 day
Test Coverage

Method validationError has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function validationError($format, $data)
    {
        switch ($format) {
            case self::DATE_TIME:
                return self::dateTimeError($data);
Severity: Minor
Found in src/Constraint/Format.php - About 1 hr to fix

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

        public static function dateTimeError($data)
        {
            if (!preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)) {
                return 'Invalid date-time format: ' . $data;
            }
    Severity: Minor
    Found in src/Constraint/Format.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

    Avoid too many return statements within this method.
    Open

                    return Iri::validationError($data);
    Severity: Major
    Found in src/Constraint/Format.php - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

                      return Iri::validationError($data, Uri::IS_URI_REFERENCE);
      Severity: Major
      Found in src/Constraint/Format.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return count(explode('@', $data, 3)) === 2 ? null : 'Invalid email';
        Severity: Major
        Found in src/Constraint/Format.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                          return filter_var($data, FILTER_VALIDATE_EMAIL) ? null : 'Invalid email';
          Severity: Major
          Found in src/Constraint/Format.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return preg_match(Uri::HOSTNAME_REGEX, $data) ? null : 'Invalid hostname';
            Severity: Major
            Found in src/Constraint/Format.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return null;
              Severity: Major
              Found in src/Constraint/Format.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return self::jsonPointerError($data, true);
                Severity: Major
                Found in src/Constraint/Format.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? null : 'Invalid ipv4';
                  Severity: Major
                  Found in src/Constraint/Format.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return Uri::validationError($data, Uri::IS_URI_REFERENCE);
                    Severity: Major
                    Found in src/Constraint/Format.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return self::jsonPointerError($data);
                      Severity: Major
                      Found in src/Constraint/Format.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                            return 'Invalid hostname (too long)';
                        Severity: Major
                        Found in src/Constraint/Format.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return IdnHostname::validationError($data);
                          Severity: Major
                          Found in src/Constraint/Format.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? null : 'Invalid ipv6';
                            Severity: Major
                            Found in src/Constraint/Format.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return self::regexError($data);
                              Severity: Major
                              Found in src/Constraint/Format.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return Uri::validationError($data, Uri::IS_URI_TEMPLATE);
                                Severity: Major
                                Found in src/Constraint/Format.php - About 30 mins to fix

                                  There are no issues that match your filters.

                                  Category
                                  Status