swaggest/php-json-schema

View on GitHub

Showing 89 of 92 total issues

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

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

<?php


use Swaggest\JsonSchema\Context;
use Swaggest\JsonSchema\InvalidValue;
Severity: Major
Found in benchmarks/AjvSchemasBench.php and 1 other location - About 4 days to fix
benchmarks/Draft7Bench.php on lines 1..144

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 789.

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

<?php


use Swaggest\JsonSchema\Context;
use Swaggest\JsonSchema\InvalidValue;
Severity: Major
Found in benchmarks/Draft7Bench.php and 1 other location - About 4 days to fix
benchmarks/AjvSchemasBench.php on lines 1..144

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 789.

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

Method unicodeValidationError has 625 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function unicodeValidationError($data, &$sanitized = null)
    {
        static $excluded = array(
            "\xD9\x80" => '\u0640',
            "\xDF\xBA" => '\u07FA',
Severity: Major
Found in src/Constraint/Format/Iri.php - About 3 days to fix

    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

      File Iri.php has 664 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace Swaggest\JsonSchema\Constraint\Format;
      
      class Iri
      Severity: Major
      Found in src/Constraint/Format/Iri.php - About 1 day 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

          Function resolveReference has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
          Open

              public function resolveReference($referencePath)
              {
                  if ($this->resolutionScope) {
                      $referencePath = Helper::resolveURI($this->resolutionScope, $referencePath);
                  }
          Severity: Minor
          Found in src/RefResolver.php - About 7 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 provider has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function provider($path)
              {
                  $testCases = array();
          
                  if ($handle = opendir($path)) {
          Severity: Minor
          Found in benchmarks/AjvSchemasBench.php - About 6 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 provider has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

              private static function provider($path)
              {
                  $testCases = array();
          
                  if ($handle = opendir($path)) {
          Severity: Minor
          Found in benchmarks/Draft7Bench.php - About 6 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 validationError has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function validationError($data, $options = 0)
              {
                  if ($options === Uri::IS_URI_TEMPLATE) {
                      $opened = false;
                      for ($i = 0; $i < strlen($data); ++$i) {
          Severity: Minor
          Found in src/Constraint/Format/Uri.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

          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 process has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function process(Context $options, $encoding, $mediaType, $data, $import = true)
                {
                    if ($import) {
                        if ($encoding !== null) {
                            switch ($encoding) {
            Severity: Minor
            Found in src/Constraint/Content.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

            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

              Function jsonSerialize has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
              Open

                  #[\ReturnTypeWillChange]
                  public function jsonSerialize()
                  {
                      $result = new \stdClass();
                      $schema = static::schema();
              Severity: Minor
              Found in src/Structure/ClassStructureTrait.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 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 getSchemaPointers has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function getSchemaPointers($path, $isURIFragmentId = false)
                    {
                        $items = explode('->', $path);
                        unset($items[0]);
                        $result = array();
                Severity: Minor
                Found in src/Path/PointerUtil.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

                Severity
                Category
                Status
                Source
                Language