swaggest/php-json-schema

View on GitHub
src/Schema.php

Summary

Maintainability
F
2 wks
Test Coverage

Function processObject has a Cognitive Complexity of 271 (exceeds 5 allowed). Consider refactoring.
Open

    private function processObject($data, Context $options, $path, $result = null)
    {
        $import = $options->import;

        $hasMapping = $this->properties !== null && isset($this->properties->__dataToProperty[$options->mapping]);
Severity: Minor
Found in src/Schema.php - About 5 days 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

File Schema.php has 1068 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Swaggest\JsonSchema;


Severity: Major
Found in src/Schema.php - About 2 days to fix

    Method processObject has 293 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function processObject($data, Context $options, $path, $result = null)
        {
            $import = $options->import;
    
            $hasMapping = $this->properties !== null && isset($this->properties->__dataToProperty[$options->mapping]);
    Severity: Major
    Found in src/Schema.php - About 1 day to fix

      Function process has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
      Open

          public function process($data, Context $options, $path = '#', $result = null)
          {
              $origData = $data;
              $import = $options->import;
      
      
      Severity: Minor
      Found in src/Schema.php - About 1 day 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

      Schema has 42 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Schema extends JsonSchema implements MetaHolder, SchemaContract, HasDefault
      {
          const ENUM_NAMES_PROPERTY = 'x-enum-names';
          const CONST_PROPERTY = 'const';
          const DEFAULT_PROPERTY = 'default';
      Severity: Minor
      Found in src/Schema.php - About 5 hrs to fix

        Function processArray has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
        Open

            private function processArray($data, Context $options, $path, $result)
            {
                $count = count($data);
                if (!$options->skipValidation) {
                    if ($this->minItems !== null && $count < $this->minItems) {
        Severity: Minor
        Found in src/Schema.php - About 5 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

        Function processNumeric has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

            private function processNumeric($data, $path)
            {
                if ($this->multipleOf !== null) {
                    $div = $data / $this->multipleOf;
                    if ($div != (int)$div && ($div = $data * (1 / $this->multipleOf)) && ($div != (int)$div)) {
        Severity: Minor
        Found in src/Schema.php - About 4 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 process has 107 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function process($data, Context $options, $path = '#', $result = null)
            {
                $origData = $data;
                $import = $options->import;
        
        
        Severity: Major
        Found in src/Schema.php - About 4 hrs to fix

          Method processArray has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function processArray($data, Context $options, $path, $result)
              {
                  $count = count($data);
                  if (!$options->skipValidation) {
                      if ($this->minItems !== null && $count < $this->minItems) {
          Severity: Major
          Found in src/Schema.php - About 2 hrs to fix

            Function processEnum has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
            Open

                private function processEnum($data, $path = '#')
                {
                    $enumOk = false;
                    foreach ($this->enum as $item) {
                        if ($item === $data ||
            Severity: Minor
            Found in src/Schema.php - About 2 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 processNumeric has 57 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function processNumeric($data, $path)
                {
                    if ($this->multipleOf !== null) {
                        $div = $data / $this->multipleOf;
                        if ($div != (int)$div && ($div = $data * (1 / $this->multipleOf)) && ($div != (int)$div)) {
            Severity: Major
            Found in src/Schema.php - About 2 hrs to fix

              Function processString has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function processString($data, $path)
                  {
                      if ($this->minLength !== null) {
                          if (mb_strlen($data, 'UTF-8') < $this->minLength) {
                              $this->fail((new StringException('String is too short', StringException::TOO_SHORT))
              Severity: Minor
              Found in src/Schema.php - About 2 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

              Function processOneOf has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function processOneOf($data, Context $options, $path)
                  {
                      $successes = 0;
                      $failures = '';
                      $subErrors = [];
              Severity: Minor
              Found in src/Schema.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 processOneOf has 45 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function processOneOf($data, Context $options, $path)
                  {
                      $successes = 0;
                      $failures = '';
                      $subErrors = [];
              Severity: Minor
              Found in src/Schema.php - About 1 hr to fix

                Function processConst has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                Open

                    private function processConst($data, $path)
                    {
                        if ($this->const !== $data &&
                            !( // Int and float equality.
                                (is_int($this->const) || is_float($this->const)) &&
                Severity: Minor
                Found in src/Schema.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 processString has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function processString($data, $path)
                    {
                        if ($this->minLength !== null) {
                            if (mb_strlen($data, 'UTF-8') < $this->minLength) {
                                $this->fail((new StringException('String is too short', StringException::TOO_SHORT))
                Severity: Minor
                Found in src/Schema.php - About 1 hr to fix

                  Method processAnyOf has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function processAnyOf($data, Context $options, $path)
                      {
                          $successes = 0;
                          $failures = '';
                          $subErrors = [];
                  Severity: Minor
                  Found in src/Schema.php - About 1 hr to fix

                    Method processEnum has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function processEnum($data, $path = '#')
                        {
                            $enumOk = false;
                            foreach ($this->enum as $item) {
                                if ($item === $data ||
                    Severity: Minor
                    Found in src/Schema.php - About 1 hr to fix

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

                          public static function import($data, Context $options = null)
                          {
                              if (null === $options) {
                                  $options = new Context();
                              }
                      Severity: Minor
                      Found in src/Schema.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 in has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function in($data, Context $options = null)
                          {
                              if (null !== $this->__booleanSchema) {
                                  if ($this->__booleanSchema) {
                                      return $data;
                      Severity: Minor
                      Found in src/Schema.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 deeply nested control flow statements.
                      Open

                                                      if ($result->__validateOnSet) {
                                                          $result->__validateOnSet = false;
                                                          /** @noinspection PhpUnusedLocalVariableInspection */
                                                          /* todo check performance impact
                                                          $validateOnSetHandler = new ScopeExit(function () use ($result) {
                      Severity: Major
                      Found in src/Schema.php - About 45 mins to fix

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

                            private function processAnyOf($data, Context $options, $path)
                            {
                                $successes = 0;
                                $failures = '';
                                $subErrors = [];
                        Severity: Minor
                        Found in src/Schema.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

                        Consider simplifying this complex logical expression.
                        Open

                                if ($this->const !== $data &&
                                    !( // Int and float equality.
                                        (is_int($this->const) || is_float($this->const)) &&
                                        (is_int($data) || is_float($data)) &&
                                        $this->const == $data
                        Severity: Major
                        Found in src/Schema.php - About 40 mins to fix

                          Consider simplifying this complex logical expression.
                          Open

                                      if ($item === $data ||
                                          ( // Int and float equality check.
                                              (is_int($item) || is_float($item)) &&
                                              (is_int($data) || is_float($data)) &&
                                              $item == $data
                          Severity: Major
                          Found in src/Schema.php - About 40 mins to fix

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

                                public function makeObjectItem(Context $options = null)
                                {
                                    if (null === $this->objectItemClass) {
                                        return new ObjectItem();
                                    } else {
                            Severity: Minor
                            Found in src/Schema.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

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

                                private function processIf($data, Context $options, $path)
                                {
                                    $valid = true;
                                    try {
                                        self::unboolSchema($this->if)->process($data, $options, $path . '->if');
                            Severity: Minor
                            Found in src/Schema.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

                            There are no issues that match your filters.

                            Category
                            Status