ruby-json-schema/json-schema

View on GitHub
lib/json-schema/validator.rb

Summary

Maintainability
F
4 days
Test Coverage

File validator.rb has 507 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'open-uri'
require 'pathname'
require 'bigdecimal'
require 'digest/sha1'
require 'date'
Severity: Major
Found in lib/json-schema/validator.rb - About 1 day to fix

    Class Validator has 47 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Validator
        @@schemas = {}
        @@cache_schemas = true
        @@default_opts = {
          list: false,
    Severity: Minor
    Found in lib/json-schema/validator.rb - About 6 hrs to fix

      Method build_schemas has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def build_schemas(parent_schema)
            schema = parent_schema.schema
      
            # Build ref schemas if they exist
            if schema['$ref']
      Severity: Minor
      Found in lib/json-schema/validator.rb - 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 initialize_schema has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize_schema(schema, default_validator)
            if schema.is_a?(String)
              begin
                # Build a fake URI for this
                schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
      Severity: Minor
      Found in lib/json-schema/validator.rb - 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 initialize_data has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize_data(data)
            if @options[:parse_data]
              if @options[:json]
                data = self.class.parse(data)
              elsif @options[:uri]
      Severity: Minor
      Found in lib/json-schema/validator.rb - 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 parse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse(s)
              if defined?(MultiJson)
                begin
                  MultiJson.respond_to?(:adapter) ? MultiJson.load(s) : MultiJson.decode(s)
                rescue MultiJson::ParseError => e
      Severity: Minor
      Found in lib/json-schema/validator.rb - 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 build_schemas has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def build_schemas(parent_schema)
            schema = parent_schema.schema
      
            # Build ref schemas if they exist
            if schema['$ref']
      Severity: Minor
      Found in lib/json-schema/validator.rb - About 1 hr to fix

        Method initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def initialize(schema_data, opts = {})
              @options = @@default_opts.clone.merge(opts)
              @errors = []
        
              configured_validator = self.class.validator_for_name(@options[:version])
        Severity: Minor
        Found in lib/json-schema/validator.rb - 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 initialize_schema has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initialize_schema(schema, default_validator)
              if schema.is_a?(String)
                begin
                  # Build a fake URI for this
                  schema_uri = JSON::Util::URI.parse(fake_uuid(schema))
        Severity: Minor
        Found in lib/json-schema/validator.rb - About 1 hr to fix

          Method json_backend= has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def json_backend=(backend)
                  if defined?(MultiJson)
                    backend = backend == 'json' ? 'json_gem' : backend
                    MultiJson.respond_to?(:use) ? MultiJson.use(backend) : MultiJson.engine = backend
                  else
          Severity: Minor
          Found in lib/json-schema/validator.rb - 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 parse has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def parse(s)
                  if defined?(MultiJson)
                    begin
                      MultiJson.respond_to?(:adapter) ? MultiJson.load(s) : MultiJson.decode(s)
                    rescue MultiJson::ParseError => e
          Severity: Minor
          Found in lib/json-schema/validator.rb - About 1 hr to fix

            Method schema_from_fragment has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def schema_from_fragment(base_schema, fragment)
                  schema_uri = base_schema.uri
                  fragments = fragment.split('/').map { |f| f.gsub('~0', '~').gsub('~1', '/') }
            
                  # ensure the first element was a hash, per the fragment spec
            Severity: Minor
            Found in lib/json-schema/validator.rb - 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

            Method merge_missing_values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def merge_missing_values(source, destination)
                    case destination
                    when Hash
                      source.each do |key, source_value|
                        destination_value = destination[key] || destination[key.to_sym]
            Severity: Minor
            Found in lib/json-schema/validator.rb - 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

            Method custom_open has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def custom_open(uri)
                  uri = Util::URI.normalized_uri(uri) if uri.is_a?(String)
                  if uri.absolute? && Util::URI::SUPPORTED_PROTOCOLS.include?(uri.scheme)
                    begin
                      URI.open(uri.to_s).read
            Severity: Minor
            Found in lib/json-schema/validator.rb - 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

            Method validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def validate(data)
                  original_data = data
                  data = initialize_data(data)
                  @base_schema.validate(data, [], self, @validation_options)
            
            
            Severity: Minor
            Found in lib/json-schema/validator.rb - 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