flexirest/flexirest

View on GitHub

Showing 83 of 103 total issues

Method has_many has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def has_many(key, klass = nil)
        if klass.nil?
          klass = key.to_s.classify.constantize
        end

Severity: Minor
Found in lib/flexirest/associations.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 perform_caching has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def perform_caching(value = nil)
        @perform_caching = nil unless instance_variable_defined?(:@perform_caching)
        if value.nil?
          value = if @perform_caching.nil?
            @@perform_caching
Severity: Minor
Found in lib/flexirest/caching.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 make_safe_request has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def make_safe_request(path, &block)
      block.call
    rescue Faraday::TimeoutError
      raise Flexirest::TimeoutException.new("Timed out getting #{full_url(path)}")
    rescue Faraday::ConnectionFailed => e1
Severity: Minor
Found in lib/flexirest/connection.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 handle_hal_links_embedded has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def handle_hal_links_embedded(object, attributes)
      attributes["_links"] = attributes[:_links] if attributes[:_links]
      attributes["_embedded"] = attributes[:_embedded] if attributes[:_embedded]
      if attributes["_links"]
        attributes["_links"].each do |key, value|
Severity: Minor
Found in lib/flexirest/request.rb - About 1 hr to fix

    Method fetch_attributes_and_relationships has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def fetch_attributes_and_relationships(record, included, rels, base: nil)
            base = Array(base) unless base.is_a?(Array)
            rels = rels - [base.last]
            rels_object = record['relationships']
    
    
    Severity: Minor
    Found in lib/flexirest/json_api_proxy.rb - About 1 hr to fix

      Method new_object has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def new_object(attributes, name = nil, parent = nil, parent_attribute_name = nil)
            @method[:options][:has_many] ||= {}
            name = name.to_sym rescue nil
            if @method[:options][:has_many][name]
              parent_name = name
      Severity: Minor
      Found in lib/flexirest/request.rb - About 1 hr to fix

        Method parse_attribute_value has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def parse_attribute_value(v)
              return v if v.is_a?(Date) || v.is_a?(DateTime) ||
                          v.kind_of?(NilClass) || v.kind_of?(TrueClass) || v.kind_of?(FalseClass) || v.kind_of?(Numeric)
        
              if v.to_s[(/\A(((19|20)\d\d[- \/.](0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9]))|((0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9])[- \/.](19|20)\d\d))\Z/)]
        Severity: Minor
        Found in lib/flexirest/attribute_parsing.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

        Avoid deeply nested control flow statements.
        Open

                      if options[:maximum]
                        @errors[validation[:field_name]] << (validation[:options][:message] || "must be no more than #{options[:maximum]} characters long") unless value.to_s.length <= options[:maximum]
                      end
        Severity: Major
        Found in lib/flexirest/validation.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                        @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
          Severity: Major
          Found in lib/flexirest/validation.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                    @body ||= if params.is_a?(String)
                      params
                    elsif @post_params.is_a?(String)
                      @post_params
                    else
            Severity: Major
            Found in lib/flexirest/request.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                            if @object.changes.has_key? changed_attr.to_sym
                              newPostHash[changed_attr.to_sym] = @object[changed_attr.to_sym]
                            end
              Severity: Major
              Found in lib/flexirest/request.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                              if options[:within]
                                @errors[validation[:field_name]] << (validation[:options][:message] || "must be within range #{options[:within]}") unless options[:within].include?(value.to_s.length )
                              end
                Severity: Major
                Found in lib/flexirest/validation.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                raise ValidationFailedException.new if respond_to?(:valid?) && !valid?
                  Severity: Major
                  Found in lib/flexirest/base_without_validation.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                              if wrap_root.present?
                                p = {wrap_root => p}
                              end
                    Severity: Major
                    Found in lib/flexirest/request.rb - About 45 mins to fix

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

                          def value_for_inspect(value)
                            if value.is_a?(String) && value.length > 50
                              "#{value[0..50]}...".inspect
                            elsif value.is_a?(Date) || value.is_a?(Time)
                              %("#{value.respond_to?(:to_fs) ? value.to_fs(:db) : value.to_s(:db)}")
                      Severity: Minor
                      Found in lib/flexirest/base_without_validation.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

                      Avoid deeply nested control flow statements.
                      Open

                                elsif type == :minimum
                                  if value.nil?
                                    @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
                                  else
                                    @errors[validation[:field_name]] << (validation[:options][:message] || "must be at least #{options}") unless value.to_f >= options.to_f
                      Severity: Major
                      Found in lib/flexirest/validation.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                      if options[:minimum]
                                        @errors[validation[:field_name]] << (validation[:options][:message] || "must be at least #{options[:minimum]} characters long") unless value.to_s.length >= options[:minimum]
                                      end
                        Severity: Major
                        Found in lib/flexirest/validation.rb - About 45 mins to fix

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

                              def each
                                if @subloaders
                                  if @subloaders.is_a? Array
                                    @subloaders.each do |loader|
                                      yield loader
                          Severity: Minor
                          Found in lib/flexirest/lazy_association_loader.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

                          Avoid deeply nested control flow statements.
                          Open

                                elsif request_body_type == :json
                                  @body ||= if params.is_a?(String)
                                    params
                                  elsif @post_params.is_a?(String)
                                    @post_params
                          Severity: Major
                          Found in lib/flexirest/request.rb - About 45 mins to fix

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

                                  def cache_store=(value)
                                    @@cache_store = nil if value.nil? and return
                                    raise InvalidCacheStoreException.new("Cache store does not implement #read") unless value.respond_to?(:read)
                                    raise InvalidCacheStoreException.new("Cache store does not implement #write") unless value.respond_to?(:write)
                                    raise InvalidCacheStoreException.new("Cache store does not implement #fetch") unless value.respond_to?(:fetch)
                            Severity: Minor
                            Found in lib/flexirest/caching.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

                            Severity
                            Category
                            Status
                            Source
                            Language