hackedteam/rcs-db

View on GitHub
lib/rcs-db/db_objects/entity.rb

Summary

Maintainability
F
4 days
Test Coverage

File entity.rb has 547 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'mongoid'
require 'lrucache'

require_relative '../link_manager'
require_relative '../position/proximity'
Severity: Major
Found in lib/rcs-db/db_objects/entity.rb - About 1 day to fix

    Method positions_flow has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.positions_flow(ids, from, to, options = {})
        ext = 70*60
    
        t = Time.at(from.to_i)
        from = Time.new(t.year, t.month, t.day, t.hour, t.min, 0).to_i
    Severity: Minor
    Found in lib/rcs-db/db_objects/entity.rb - About 7 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 Entity has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Entity
      extend RCS::Tracer
      include RCS::Tracer
      include Mongoid::Document
      include Mongoid::Timestamps
    Severity: Minor
    Found in lib/rcs-db/db_objects/entity.rb - About 4 hrs to fix

      Method flow has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.flow(params)
          start_time = Time.now # for debugging
      
          # aggregate all the entities by their handles' handle
          # so if 2 entities share the same handle you'll get {'foo.bar@gmail.com' => ['entity1_id', 'entity2_id']}
      Severity: Minor
      Found in lib/rcs-db/db_objects/entity.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 positions_flow has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.positions_flow(ids, from, to, options = {})
          ext = 70*60
      
          t = Time.at(from.to_i)
          from = Time.new(t.year, t.month, t.day, t.hour, t.min, 0).to_i
      Severity: Major
      Found in lib/rcs-db/db_objects/entity.rb - About 2 hrs to fix

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

          def self.name_from_handle(type, handle, target_id)
        
            # use a class cache
            @@acc_cache ||= LRUCache.new(:ttl => 24.hour)
        
        
        Severity: Minor
        Found in lib/rcs-db/db_objects/entity.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 flow has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.flow(params)
            start_time = Time.now # for debugging
        
            # aggregate all the entities by their handles' handle
            # so if 2 entities share the same handle you'll get {'foo.bar@gmail.com' => ['entity1_id', 'entity2_id']}
        Severity: Minor
        Found in lib/rcs-db/db_objects/entity.rb - About 1 hr to fix

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

            def self.create_or_update_group(operation, name: nil, children: [], stand_for: nil)
              children = children[0].respond_to?(:id) ? children.map(&:id) : children
              level = stand_for ? :automatic : :manual
              operation = operation.respond_to?(:id) ? operation : Item.operations.find(operation)
          
          
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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 link_target_entities_passed_from_here has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def link_target_entities_passed_from_here
              return if type != :position
          
              operation_id = path.first
          
          
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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 handle_regexp_for_queries has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.handle_regexp_for_queries(type, value)
              if type.to_s != 'phone'
                value
              else
                # if the type is phone but the value contains no numbers
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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 linked_to? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def linked_to? another_entity, options = {}
              filter = {}
              filter[:type] = options[:type] if options[:type]
              filter[:level] = options[:level] if options[:level]
          
          
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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 create_or_update_operation_group has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.create_or_update_operation_group(first_operation, second_operation)
              first_operation = Item.operations.find(first_operation) unless first_operation.respond_to?(:id)
              second_operation = Item.operations.find(second_operation) unless second_operation.respond_to?(:id)
          
              first_op_name, second_op_name = *[first_operation.name, second_operation.name].map do |name|
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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 merge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

            def merge(merging)
              raise "cannot merge a target over a person" if merging.type == :target
              raise "cannot merge different type of entities" unless [:person, :target].include? self.type and [:person, :target].include? merging.type
          
              trace :debug, "Merging entities: #{merging.name} -> #{self.name}"
          Severity: Minor
          Found in lib/rcs-db/db_objects/entity.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

          Avoid too many return statements within this method.
          Open

                return e[:data]['name']
          Severity: Major
          Found in lib/rcs-db/db_objects/entity.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                return nil
            Severity: Major
            Found in lib/rcs-db/db_objects/entity.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                  return nil
              Severity: Major
              Found in lib/rcs-db/db_objects/entity.rb - About 30 mins to fix

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

                  def link_similar_position
                    return if type != :position
                    return if level != :manual
                
                    self.class.same_path_of(self).positions_within(position, 100).each do |other_entity|
                Severity: Minor
                Found in lib/rcs-db/db_objects/entity.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