openjaf/cenit

View on GitHub
app/models/setup/schema_handler.rb

Summary

Maintainability
F
6 days
Test Coverage

Method do_merge_schema has a Cognitive Complexity of 139 (exceeds 5 allowed). Consider refactoring.
Open

    def do_merge_schema(schema, options = {})
      if schema.is_a?(Array)
        return schema.collect { |sch| do_merge_schema(sch, options) }
      end
      return schema unless schema.is_a?(Hash)
Severity: Minor
Found in app/models/setup/schema_handler.rb - About 2 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

Method check_properties has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
Open

    def check_properties(json_schema, options = {})
      object_schema =
        case json_schema['type']
        when 'object'
          json_schema
Severity: Minor
Found in app/models/setup/schema_handler.rb - 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

Method do_merge_schema has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def do_merge_schema(schema, options = {})
      if schema.is_a?(Array)
        return schema.collect { |sch| do_merge_schema(sch, options) }
      end
      return schema unless schema.is_a?(Hash)
Severity: Major
Found in app/models/setup/schema_handler.rb - About 3 hrs to fix

    Method check_properties has 75 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def check_properties(json_schema, options = {})
          object_schema =
            case json_schema['type']
            when 'object'
              json_schema
    Severity: Major
    Found in app/models/setup/schema_handler.rb - About 3 hrs to fix

      Method get_embedded_schema has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_embedded_schema(ref, root_schema, root_name = '')
            fail "invalid format for embedded reference #{ref}" unless ref =~ %r{\A#(\/[a-z]+(_|([0-9]|[a-z])+)*)*\Z}
            fail "embedding itself (referencing '#')" if ref.eql?('#')
            tokens = ref.split('/')
            tokens.shift
      Severity: Minor
      Found in app/models/setup/schema_handler.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

      Avoid deeply nested control flow statements.
      Open

                    fail "contains an unresolved reference #{ref}" unless options[:silent]
      Severity: Major
      Found in app/models/setup/schema_handler.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    base_model = find_ref_schema(base_model) if base_model.is_a?(String)
        Severity: Major
        Found in app/models/setup/schema_handler.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                          value = existing_value.deep_merge(value) { |_, sch_value, ref_value| Cenit::Utility.array_hash_merge(sch_value, ref_value) } if value.is_a?(Hash)
          Severity: Major
          Found in app/models/setup/schema_handler.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                          if schema['type'] == 'object' && base_model['type'] != 'object'
                            schema['properties'] ||= {}
                            value_schema = schema['properties']['value'] || {}
                            value_schema = base_model.deep_merge(value_schema)
                            schema['properties']['value'] = value_schema.merge('title' => 'Value', 'xml' => { 'content' => true })
            Severity: Major
            Found in app/models/setup/schema_handler.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          schema = { 'properties' => base_properties }.deep_merge(schema) do |_, ref_value, sch_value|
                            Cenit::Utility.array_hash_merge(ref_value, sch_value)
                          end unless base_properties.blank?
              Severity: Major
              Found in app/models/setup/schema_handler.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                value += existing_value if value.is_a?(Array)
                Severity: Major
                Found in app/models/setup/schema_handler.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              schema['extends'] = base_model['extends'] if base_model['extends']
                  Severity: Major
                  Found in app/models/setup/schema_handler.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                next unless (base_properties = base_model['properties'])
                    Severity: Major
                    Found in app/models/setup/schema_handler.rb - About 45 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status