ruby-grape/grape

View on GitHub
lib/grape/validations/params_scope.rb

Summary

Maintainability
D
2 days
Test Coverage

Class ParamsScope has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

    class ParamsScope
      attr_accessor :element, :parent, :index
      attr_reader :type

      include Grape::DSL::Parameters
Severity: Minor
Found in lib/grape/validations/params_scope.rb - About 4 hrs to fix

    File params_scope.rb has 322 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative 'attributes_doc'
    
    module Grape
      module Validations
        class ParamsScope
    Severity: Minor
    Found in lib/grape/validations/params_scope.rb - About 3 hrs to fix

      Method infer_coercion has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

            def infer_coercion(validations)
              raise ArgumentError, ':type may not be supplied with :types' if validations.key?(:type) && validations.key?(:types)
      
              validations[:coerce] = (options_key?(:type, :value, validations) ? validations[:type][:value] : validations[:type]) if validations.key?(:type)
              validations[:coerce_message] = (options_key?(:type, :message, validations) ? validations[:type][:message] : nil) if validations.key?(:type)
      Severity: Minor
      Found in lib/grape/validations/params_scope.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 validate_value_coercion has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

            def validate_value_coercion(coerce_type, *values_list)
              return unless coerce_type
      
              coerce_type = coerce_type.first if coerce_type.is_a?(Array)
              values_list.each do |values|
      Severity: Minor
      Found in lib/grape/validations/params_scope.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 new_scope has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def new_scope(attrs, optional = false, &block)
              # if required params are grouped and no type or unsupported type is provided, raise an error
              type = attrs[1] ? attrs[1][:type] : nil
              if attrs.first && !optional
                raise Grape::Exceptions::MissingGroupType if type.nil?
      Severity: Minor
      Found in lib/grape/validations/params_scope.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 meets_hash_dependency? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def meets_hash_dependency?(params)
              # params might be anything what looks like a hash, so it must implement a `key?` method
              return false unless params.respond_to?(:key?)
      
              @dependent_on.each do |dependency|
      Severity: Minor
      Found in lib/grape/validations/params_scope.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 check_incompatible_option_values has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def check_incompatible_option_values(default, values, except_values, excepts)
              return unless default && !default.is_a?(Proc)
      
              raise Grape::Exceptions::IncompatibleOptionValues.new(:default, default, :values, values) if values && !values.is_a?(Proc) && !Array(default).all? { |def_val| values.include?(def_val) }
      
      
      Severity: Minor
      Found in lib/grape/validations/params_scope.rb - 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

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

            def guess_coerce_type(coerce_type, *values_list)
              return coerce_type unless coerce_type == Array
      
              values_list.each do |values|
                next if !values || values.is_a?(Proc)
      Severity: Minor
      Found in lib/grape/validations/params_scope.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 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

            def validate(type, options, attrs, doc, opts)
      Severity: Minor
      Found in lib/grape/validations/params_scope.rb - About 35 mins to fix

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

              def push_declared_params(attrs, **opts)
                opts = opts.merge(declared_params_scope: self) unless opts.key?(:declared_params_scope)
                if lateral?
                  @parent.push_declared_params(attrs, **opts)
                else
        Severity: Minor
        Found in lib/grape/validations/params_scope.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

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

              def validates(attrs, validations)
                doc = AttributesDoc.new @api, self
                doc.extract_details validations
        
                coerce_type = infer_coercion(validations)
        Severity: Minor
        Found in lib/grape/validations/params_scope.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

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

              def require_required_and_optional_fields(context, opts)
                if context == :all
                  optional_fields = Array(opts[:except])
                  required_fields = opts[:using].keys - optional_fields
                else # context == :none
        Severity: Minor
        Found in lib/grape/validations/params_scope.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

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

              def extract_message_option(attrs)
                return nil unless attrs.is_a?(Array)
        
                opts = attrs.last.is_a?(Hash) ? attrs.pop : {}
                opts.key?(:message) && !opts[:message].nil? ? opts.delete(:message) : nil
        Severity: Minor
        Found in lib/grape/validations/params_scope.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

        Method meets_dependency? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def meets_dependency?(params, request_params)
                return true unless @dependent_on
        
                return false if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)
        
        
        Severity: Minor
        Found in lib/grape/validations/params_scope.rb - About 25 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 should_validate? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def should_validate?(parameters)
                scoped_params = params(parameters)
        
                return false if @optional && (scoped_params.blank? || all_element_blank?(scoped_params))
                return false unless meets_dependency?(scoped_params, parameters)
        Severity: Minor
        Found in lib/grape/validations/params_scope.rb - About 25 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