flexirest/flexirest

View on GitHub

Showing 103 of 103 total issues

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

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

            def self.warn(message)
              if defined?(Rails) && Rails.logger.present?
                Rails.logger.warn(message)
              elsif @logfile
                if @logfile.is_a?(String)
        Severity: Major
        Found in lib/flexirest/logger.rb and 3 other locations - About 45 mins to fix
        lib/flexirest/logger.rb on lines 27..40
        lib/flexirest/logger.rb on lines 43..56
        lib/flexirest/logger.rb on lines 75..88

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

        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 4 locations. Consider refactoring.
        Open

            def self.debug(message)
              if defined?(Rails) && Rails.logger.present?
                Rails.logger.debug(message)
              elsif @logfile
                if @logfile.is_a?(String)
        Severity: Major
        Found in lib/flexirest/logger.rb and 3 other locations - About 45 mins to fix
        lib/flexirest/logger.rb on lines 43..56
        lib/flexirest/logger.rb on lines 59..72
        lib/flexirest/logger.rb on lines 75..88

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

        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 4 locations. Consider refactoring.
        Open

            def self.error(message)
              if defined?(Rails) && Rails.logger.present?
                Rails.logger.error(message)
              elsif @logfile
                if @logfile.is_a?(String)
        Severity: Major
        Found in lib/flexirest/logger.rb and 3 other locations - About 45 mins to fix
        lib/flexirest/logger.rb on lines 27..40
        lib/flexirest/logger.rb on lines 43..56
        lib/flexirest/logger.rb on lines 59..72

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

        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 4 locations. Consider refactoring.
        Open

            def self.info(message)
              if defined?(Rails) && Rails.logger.present?
                Rails.logger.info(message)
              elsif @logfile
                if @logfile.is_a?(String)
        Severity: Major
        Found in lib/flexirest/logger.rb and 3 other locations - About 45 mins to fix
        lib/flexirest/logger.rb on lines 27..40
        lib/flexirest/logger.rb on lines 59..72
        lib/flexirest/logger.rb on lines 75..88

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

        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

        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

          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

                        if value.nil?
                          @errors[validation[:field_name]] << (validation[:options][:message] || "must be not be nil") unless allow_nil
                        else
                          numeric = (true if Float(value) rescue false)
                          if !numeric
            Severity: Major
            Found in lib/flexirest/validation.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

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

                                  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
                      Severity
                      Category
                      Status
                      Source
                      Language