zammad/zammad

View on GitHub
app/models/object_manager/attribute.rb

Summary

Maintainability
F
5 days
Test Coverage

File attribute.rb has 832 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ObjectManager::Attribute < ApplicationModel
  include HasDefaultModelUserRelations

  include ChecksClientNotification
  include CanSeed
Severity: Major
Found in app/models/object_manager/attribute.rb - About 2 days to fix

    Method migration_execute has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.migration_execute(send_event = true)
    
        # check if field already exists
        execute_db_count = 0
        execute_config_count = 0
    Severity: Minor
    Found in app/models/object_manager/attribute.rb - About 6 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 migration_execute has 159 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.migration_execute(send_event = true)
    
        # check if field already exists
        execute_db_count = 0
        execute_config_count = 0
    Severity: Major
    Found in app/models/object_manager/attribute.rb - About 6 hrs to fix

      Method add has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.add(data)
          force = data[:force]
          data.delete(:force)
      
          # lookups
      Severity: Minor
      Found in app/models/object_manager/attribute.rb - About 4 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

      Class Attribute has 36 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class ObjectManager::Attribute < ApplicationModel
        include HasDefaultModelUserRelations
      
        include ChecksClientNotification
        include CanSeed
      Severity: Minor
      Found in app/models/object_manager/attribute.rb - About 4 hrs to fix

        Method add has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.add(data)
            force = data[:force]
            data.delete(:force)
        
            # lookups
        Severity: Major
        Found in app/models/object_manager/attribute.rb - About 2 hrs to fix

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

            def check_name
              return if !name
          
              if name.match?(%r{.+?_(id|ids)$}i)
                errors.add(:name, __("can't be used because *_id and *_ids are not allowed"))
          Severity: Minor
          Found in app/models/object_manager/attribute.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 check_name has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def check_name
              return if !name
          
              if name.match?(%r{.+?_(id|ids)$}i)
                errors.add(:name, __("can't be used because *_id and *_ids are not allowed"))
          Severity: Minor
          Found in app/models/object_manager/attribute.rb - About 1 hr to fix

            Method remove has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.remove(data)
            
                # lookups
                if data[:object]
                  data[:object_lookup_id] = ObjectLookup.by_name(data[:object])
            Severity: Minor
            Found in app/models/object_manager/attribute.rb - About 1 hr to fix

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

                def self.remove(data)
              
                  # lookups
                  if data[:object]
                    data[:object_lookup_id] = ObjectLookup.by_name(data[:object])
              Severity: Minor
              Found in app/models/object_manager/attribute.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 attribute_used_by_references has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.attribute_used_by_references(object_name, attribute_name, references = attribute_to_references_hash)
                  result = {}
                  references.each do |reference_key, relations|
                    local_object, local_attribute = reference_key.split('.')
                    next if local_object != object_name.downcase
              Severity: Minor
              Found in app/models/object_manager/attribute.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 set_base_options has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def set_base_options
                  local_data_option[:null] = true if local_data_option[:null].nil?
              
                  case data_type
                  when %r{^((multi|tree_)?select|checkbox)$}
              Severity: Minor
              Found in app/models/object_manager/attribute.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 attribute_to_references_hash has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.attribute_to_references_hash
                  attribute_list = {}
              
                  attribute_to_references_hash_objects
                    .map { |elem| elem.select(:name, :condition) }
              Severity: Minor
              Found in app/models/object_manager/attribute.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

              Method attribute_used_by_references? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.attribute_used_by_references?(object_name, attribute_name, references = attribute_to_references_hash)
                  references.each_key do |reference_key|
                    local_object, local_attribute = reference_key.split('.')
                    next if local_object != object_name.downcase
                    next if local_attribute != attribute_name
              Severity: Minor
              Found in app/models/object_manager/attribute.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

              There are no issues that match your filters.

              Category
              Status