SpeciesFileGroup/taxonworks

View on GitHub
app/models/sled_image.rb

Summary

Maintainability
C
1 day
Test Coverage

Method has too many lines. [39/25]
Open

  def create_objects
    return true unless !collection_object_params.nil?
    begin
      metadata.each do |i|
        next unless i['metadata'].blank?
Severity: Minor
Found in app/models/sled_image.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class SledImage has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class SledImage < ApplicationRecord
  include Housekeeping
  include Shared::Tags
  include Shared::Notes
  include Shared::IsData
Severity: Minor
Found in app/models/sled_image.rb - About 2 hrs to fix

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

      def create_objects
        return true unless !collection_object_params.nil?
        begin
          metadata.each do |i|
            next unless i['metadata'].blank?
    Severity: Minor
    Found in app/models/sled_image.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 increment_matrix has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def increment_matrix
        i = []
        j = identity_matrix
        k = 0
        case step_identifier_on
    Severity: Minor
    Found in app/models/sled_image.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 create_objects has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create_objects
        return true unless !collection_object_params.nil?
        begin
          metadata.each do |i|
            next unless i['metadata'].blank?
    Severity: Minor
    Found in app/models/sled_image.rb - About 1 hr to fix

      Method syncronize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def syncronize
          if metadata_was == []
            process if !metadata&.empty?
          else
            # At this point we only allow coordinate updates
      Severity: Minor
      Found in app/models/sled_image.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 get_identifier_matrix has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_identifier_matrix
          i = increment_matrix
      
          m = []
      
      
      Severity: Minor
      Found in app/models/sled_image.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 is_metadata_depiction? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def is_metadata_depiction?
          if depiction_params && !depiction_params.empty?
            a = depiction_params[:is_metadata_depiction]
            ((a == 'true') || (a == true)) ? true : false
          else
      Severity: Minor
      Found in app/models/sled_image.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

      Prefer self[:attr] = val over write_attribute(:attr, val).
      Open

            write_attribute(:metadata, [])
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of the read_attribute or write_attribute methods and recommends square brackets instead.

      If an attribute is missing from the instance (for example, when initialized by a partial select) then read_attribute will return nil, but square brackets will raise an ActiveModel::MissingAttributeError.

      Explicitly raising an error in this situation is preferable, and that is why rubocop recommends using square brackets.

      Example:

      # bad
      x = read_attribute(:attr)
      write_attribute(:attr, val)
      
      # good
      x = self[:attr]
      self[:attr] = val

      Use s['metadata'].present? instead of !s['metadata'].blank?.
      Open

            next if !s['metadata'].blank? || _first_identifier.nil?
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

      Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

      Example: NotNilAndNotEmpty: true (default)

      # Converts usages of `!nil? && !empty?` to `present?`
      
      # bad
      !foo.nil? && !foo.empty?
      
      # bad
      foo != nil && !foo.empty?
      
      # good
      foo.present?

      Example: NotBlank: true (default)

      # Converts usages of `!blank?` to `present?`
      
      # bad
      !foo.blank?
      
      # bad
      not foo.blank?
      
      # good
      foo.present?

      Example: UnlessBlank: true (default)

      # Converts usages of `unless blank?` to `if present?`
      
      # bad
      something unless foo.blank?
      
      # good
      something if foo.present?

      Use find_by instead of where.first.
      Open

          depictions.where(sled_image_x_position: x, sled_image_y_position: y).first
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop is used to identify usages of where.first and change them to use find_by instead.

      Example:

      # bad
      User.where(name: 'Bruce').first
      User.where(name: 'Bruce').take
      
      # good
      User.find_by(name: 'Bruce')

      Use s['metadata'].present? instead of !s['metadata'].blank?.
      Open

            m[r][c] = nil if !s['metadata'].blank?
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

      Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

      Example: NotNilAndNotEmpty: true (default)

      # Converts usages of `!nil? && !empty?` to `present?`
      
      # bad
      !foo.nil? && !foo.empty?
      
      # bad
      foo != nil && !foo.empty?
      
      # good
      foo.present?

      Example: NotBlank: true (default)

      # Converts usages of `!blank?` to `present?`
      
      # bad
      !foo.blank?
      
      # bad
      not foo.blank?
      
      # good
      foo.present?

      Example: UnlessBlank: true (default)

      # Converts usages of `unless blank?` to `if present?`
      
      # bad
      something unless foo.blank?
      
      # good
      something if foo.present?

      Avoid using update_columns because it skips validations.
      Open

          update_columns(
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of methods which skip validations which are listed in https://guides.rubyonrails.org/active_record_validations.html#skipping-validations

      Methods may be ignored from this rule by configuring a Whitelist.

      Example:

      # bad
      Article.first.decrement!(:view_count)
      DiscussionBoard.decrement_counter(:post_count, 5)
      Article.first.increment!(:view_count)
      DiscussionBoard.increment_counter(:post_count, 5)
      person.toggle :active
      product.touch
      Billing.update_all("category = 'authorized', author = 'David'")
      user.update_attribute(:website, 'example.com')
      user.update_columns(last_request_at: Time.current)
      Post.update_counters 5, comment_count: -1, action_count: 1
      
      # good
      user.update(website: 'example.com')
      FileUtils.touch('file')

      Example: Whitelist: ["touch"]

      # bad
      DiscussionBoard.decrement_counter(:post_count, 5)
      DiscussionBoard.increment_counter(:post_count, 5)
      person.toggle :active
      
      # good
      user.touch

      Prefer self[:attr] = val over write_attribute(:attr, val).
      Open

            write_attribute(:metadata, value)
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of the read_attribute or write_attribute methods and recommends square brackets instead.

      If an attribute is missing from the instance (for example, when initialized by a partial select) then read_attribute will return nil, but square brackets will raise an ActiveModel::MissingAttributeError.

      Explicitly raising an error in this situation is preferable, and that is why rubocop recommends using square brackets.

      Example:

      # bad
      x = read_attribute(:attr)
      write_attribute(:attr, val)
      
      # good
      x = self[:attr]
      self[:attr] = val

      Avoid using update_columns because it skips validations.
      Open

                d.update_columns(
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of methods which skip validations which are listed in https://guides.rubyonrails.org/active_record_validations.html#skipping-validations

      Methods may be ignored from this rule by configuring a Whitelist.

      Example:

      # bad
      Article.first.decrement!(:view_count)
      DiscussionBoard.decrement_counter(:post_count, 5)
      Article.first.increment!(:view_count)
      DiscussionBoard.increment_counter(:post_count, 5)
      person.toggle :active
      product.touch
      Billing.update_all("category = 'authorized', author = 'David'")
      user.update_attribute(:website, 'example.com')
      user.update_columns(last_request_at: Time.current)
      Post.update_counters 5, comment_count: -1, action_count: 1
      
      # good
      user.update(website: 'example.com')
      FileUtils.touch('file')

      Example: Whitelist: ["touch"]

      # bad
      DiscussionBoard.decrement_counter(:post_count, 5)
      DiscussionBoard.increment_counter(:post_count, 5)
      person.toggle :active
      
      # good
      user.touch

      Prefer self[:attr] = val over write_attribute(:attr, val).
      Open

            write_attribute(:metadata, JSON.parse(value))
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of the read_attribute or write_attribute methods and recommends square brackets instead.

      If an attribute is missing from the instance (for example, when initialized by a partial select) then read_attribute will return nil, but square brackets will raise an ActiveModel::MissingAttributeError.

      Explicitly raising an error in this situation is preferable, and that is why rubocop recommends using square brackets.

      Example:

      # bad
      x = read_attribute(:attr)
      write_attribute(:attr, val)
      
      # good
      x = self[:attr]
      self[:attr] = val

      Use if i['metadata'].present? instead of unless i['metadata'].blank?.
      Open

              next unless i['metadata'].blank?
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

      Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

      Example: NotNilAndNotEmpty: true (default)

      # Converts usages of `!nil? && !empty?` to `present?`
      
      # bad
      !foo.nil? && !foo.empty?
      
      # bad
      foo != nil && !foo.empty?
      
      # good
      foo.present?

      Example: NotBlank: true (default)

      # Converts usages of `!blank?` to `present?`
      
      # bad
      !foo.blank?
      
      # bad
      not foo.blank?
      
      # good
      foo.present?

      Example: UnlessBlank: true (default)

      # Converts usages of `unless blank?` to `if present?`
      
      # bad
      something unless foo.blank?
      
      # good
      something if foo.present?

      Use depiction_params.present? instead of depiction_params && !depiction_params.empty?.
      Open

          if depiction_params && !depiction_params.empty?
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for code that can be written with simpler conditionals using Object#present? defined by Active Support.

      Interaction with Style/UnlessElse: The configuration of NotBlank will not produce an offense in the context of unless else if Style/UnlessElse is inabled. This is to prevent interference between the auto-correction of the two cops.

      Example: NotNilAndNotEmpty: true (default)

      # Converts usages of `!nil? && !empty?` to `present?`
      
      # bad
      !foo.nil? && !foo.empty?
      
      # bad
      foo != nil && !foo.empty?
      
      # good
      foo.present?

      Example: NotBlank: true (default)

      # Converts usages of `!blank?` to `present?`
      
      # bad
      !foo.blank?
      
      # bad
      not foo.blank?
      
      # good
      foo.present?

      Example: UnlessBlank: true (default)

      # Converts usages of `unless blank?` to `if present?`
      
      # bad
      something unless foo.blank?
      
      # good
      something if foo.present?

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

          when 'column'
            (0.._column_total).each do |c|
              (0.._row_total).each do |r|
                k += j[r][c]
                i[r] ||= []
      Severity: Minor
      Found in app/models/sled_image.rb and 1 other location - About 55 mins to fix
      app/models/sled_image.rb on lines 151..156

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

      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

          when 'row'
            (0.._row_total).each do |r|
              (0.._column_total).each do |c|
                k += j[r][c]
                i[r] ||= []
      Severity: Minor
      Found in app/models/sled_image.rb and 1 other location - About 55 mins to fix
      app/models/sled_image.rb on lines 160..165

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

      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

      Prefer the new style validations validates :column, uniqueness: value over validates_uniqueness_of.
      Open

        validates_uniqueness_of :image_id
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of old-style attribute validation macros.

      Example:

      # bad
      validates_acceptance_of :foo
      validates_confirmation_of :foo
      validates_exclusion_of :foo
      validates_format_of :foo
      validates_inclusion_of :foo
      validates_length_of :foo
      validates_numericality_of :foo
      validates_presence_of :foo
      validates_absence_of :foo
      validates_size_of :foo
      validates_uniqueness_of :foo
      
      # good
      validates :foo, acceptance: true
      validates :foo, confirmation: true
      validates :foo, exclusion: true
      validates :foo, format: true
      validates :foo, inclusion: true
      validates :foo, length: true
      validates :foo, numericality: true
      validates :foo, presence: true
      validates :foo, absence: true
      validates :foo, size: true
      validates :foo, uniqueness: true

      Useless private access modifier.
      Open

        private
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

      Example:

      class Foo
        public # this is redundant (default access is public)
      
        def method
        end
      
        private # this is not redundant (a method is defined)
        def method2
        end
      
        private # this is redundant (no following methods are defined)
      end

      Example:

      class Foo
        # The following is not redundant (conditionally defined methods are
        # considered as always defining a method)
        private
      
        if condition?
          def method
          end
        end
      
        protected # this is not redundant (method is defined)
      
        define_method(:method2) do
        end
      
        protected # this is redundant (repeated from previous modifier)
      
        [1,2,3].each do |i|
          define_method("foo#{i}") do
          end
        end
      
        # The following is redundant (methods defined on the class'
        # singleton class are not affected by the public modifier)
        public
      
        def self.method3
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   ContextCreatingMethods:
      #     - concerning
      require 'active_support/concern'
      class Foo
        concerning :Bar do
          def some_public_method
          end
      
          private
      
          def some_private_method
          end
        end
      
        # this is not redundant because `concerning` created its own context
        private
      
        def some_other_private_method
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   MethodCreatingMethods:
      #     - delegate
      require 'active_support/core_ext/module/delegation'
      class Foo
        # this is not redundant because `delegate` creates methods
        private
      
        delegate :method_a, to: :method_b
      end

      Prefer the new style validations validates :column, presence: value over validates_presence_of.
      Open

        validates_presence_of :image
      Severity: Minor
      Found in app/models/sled_image.rb by rubocop

      This cop checks for the use of old-style attribute validation macros.

      Example:

      # bad
      validates_acceptance_of :foo
      validates_confirmation_of :foo
      validates_exclusion_of :foo
      validates_format_of :foo
      validates_inclusion_of :foo
      validates_length_of :foo
      validates_numericality_of :foo
      validates_presence_of :foo
      validates_absence_of :foo
      validates_size_of :foo
      validates_uniqueness_of :foo
      
      # good
      validates :foo, acceptance: true
      validates :foo, confirmation: true
      validates :foo, exclusion: true
      validates :foo, format: true
      validates :foo, inclusion: true
      validates :foo, length: true
      validates :foo, numericality: true
      validates :foo, presence: true
      validates :foo, absence: true
      validates :foo, size: true
      validates :foo, uniqueness: true

      There are no issues that match your filters.

      Category
      Status