sanger/sequencescape

View on GitHub
app/models/api/base.rb

Summary

Maintainability
B
6 hrs
Test Coverage
C
72%

Method render_class_for_model has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def render_class_for_model(model) # rubocop:todo Metrics/CyclomaticComplexity
      render_class = Class.new(self)

      # NOTE: It's quite annoying that you don't have any access to the inheritable class attributes from
      # within the Class.new block above, so we have to do a separate instance_eval to get it to work.
Severity: Minor
Found in app/models/api/base.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 convert_json_attributes_to_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def convert_json_attributes_to_attributes(json_attributes) # rubocop:todo Metrics/AbcSize
      return {} if json_attributes.blank?

      attributes = {}
      attribute_to_json_attribute_mappings.each do |attribute, json_attribute|
Severity: Minor
Found in app/models/api/base.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 to_hash has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def to_hash(object) # rubocop:todo Metrics/CyclomaticComplexity
      # If the object is nil we get a chance to use the 'default' object that was specified.  By
      # default the "default" object is nil, but you can override it for associations through the
      # with_association(:name, :if_nil_use => :some_method).
      object ||= default_object
Severity: Minor
Found in app/models/api/base.rb - About 1 hr to fix

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

        def json_attribute_for_attribute(attribute_or_association, *rest) # rubocop:todo Metrics/AbcSize
          json_attribute = attribute_to_json_attribute_mappings[attribute_or_association.to_sym]
          if json_attribute.blank?
            # If we have reached the end of the line, and the attribute_or_association is for what looks like
            # an association, then we'll look it up without the '_id' and return that value.
    Severity: Minor
    Found in app/models/api/base.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 with_association has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.with_association(association, options = {}, &block) # rubocop:todo Metrics/AbcSize
        association_helper = Class.new(Api::Base)
        association_helper.class_eval(&block)
        association_helper.singleton_class.class_eval do
          alias_method(:default_object, options[:if_nil_use]) if options.key?(:if_nil_use)
    Severity: Minor
    Found in app/models/api/base.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 with_nested_has_many_association has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.with_nested_has_many_association(association, options = {}, &block) # rubocop:todo Metrics/AbcSize
        association_helper = Class.new(Api::Base)
        association_helper.class_eval(&block)
        association_helper.singleton_class.class_eval do
          define_method(:association) { association }
    Severity: Minor
    Found in app/models/api/base.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 newer_than has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.newer_than(object, timestamp) # rubocop:todo Metrics/CyclomaticComplexity
        return if object.nil? || timestamp.nil?
    
        modified, object_timestamp = false, (object.respond_to?(:updated_at) ? object.updated_at : timestamp) || timestamp
        timestamp, modified = object_timestamp, true if object_timestamp > timestamp
    Severity: Minor
    Found in app/models/api/base.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

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

                object.roles.each do |role|
                  json_attributes[role.name.underscore] = role.users.map do |user|
                    { login: user.login, email: user.email, name: user.name }
    Severity: Minor
    Found in app/models/api/base.rb and 1 other location - About 15 mins to fix
    app/models/api/project_io.rb on lines 44..46

    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

    There are no issues that match your filters.

    Category
    Status