krautcomputing/skimlinks

View on GitHub

Showing 9 of 9 total issues

Method search_params has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def search_params(args = {})
      args = args.dup.reverse_merge(
        ATTRIBUTES.each_with_object({}) do |attribute, hash|
          hash[attribute.to_sym] = self.send(attribute) unless self.send(attribute).nil?
        end
Severity: Minor
Found in lib/skimlinks/product_search.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 get has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def get(api, path, params = {})
      raise Skimlinks::InvalidParameters, 'Only JSON format is supported right now.' unless Skimlinks.configuration.format == :json

      do_get = lambda do
        returning_json do
Severity: Minor
Found in lib/skimlinks/client.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 merchants has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def merchants(args = {})
      args = args.dup.reverse_merge(
        ATTRIBUTES.each_with_object({}) do |attribute, hash|
          hash[attribute.to_sym] = self.send(attribute) unless self.send(attribute).nil?
        end
Severity: Minor
Found in lib/skimlinks/merchant_search.rb - About 1 hr to fix

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

        def product_count_and_products(args)
          api_query = []
          api_query << %(id:(#{args[:ids].join(' ')}))                                                          if args[:ids].present?
          api_query << %((#{%w(title description).map { |field| %(#{field}:"#{args[:query]}") }.join(' OR ')})) if args[:query].present?
          api_query << %(price:[#{args[:min_price].presence || '*'} TO #{args[:max_price].presence || '*'}])    if args[:min_price].present? || args[:max_price].present?
    Severity: Minor
    Found in lib/skimlinks/client.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 merchant_search has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def merchant_search(query, preferred = false)
          [].tap do |merchants|
            start, found = 0, nil
    
            while found.nil? || start < found
    Severity: Minor
    Found in lib/skimlinks/client.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 merchants has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def merchants(args = {})
          args = args.dup.reverse_merge(
            ATTRIBUTES.each_with_object({}) do |attribute, hash|
              hash[attribute.to_sym] = self.send(attribute) unless self.send(attribute).nil?
            end
    Severity: Minor
    Found in lib/skimlinks/merchant_search.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 merchants_in_category has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def merchants_in_category(category_id)
          [].tap do |merchants|
            start, found = 0, nil
    
            while found.nil? || start < found
    Severity: Minor
    Found in lib/skimlinks/client.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

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

          raise Skimlinks::InvalidParameters, "Currency #{args[:currency]} is not a valid currency. Valid currencies are: #{CURRENCIES.join(', ')}" if args[:currency].present? && !CURRENCIES.include?(args[:currency])
    
          category_ids = if args[:category].present?
    Severity: Minor
    Found in lib/skimlinks/product_search.rb and 1 other location - About 15 mins to fix
    lib/skimlinks/product_search.rb on lines 63..64

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

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

          raise Skimlinks::InvalidParameters, "Country #{args[:country]} is not a valid country. Valid countries are: #{COUNTRIES.join(', ')}" if args[:country].present? && !COUNTRIES.include?(args[:country])
          raise Skimlinks::InvalidParameters, "Currency #{args[:currency]} is not a valid currency. Valid currencies are: #{CURRENCIES.join(', ')}" if args[:currency].present? && !CURRENCIES.include?(args[:currency])
    Severity: Minor
    Found in lib/skimlinks/product_search.rb and 1 other location - About 15 mins to fix
    lib/skimlinks/product_search.rb on lines 64..66

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

    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

    Severity
    Category
    Status
    Source
    Language