hackedteam/rcs-db

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

Summary

Maintainability
F
3 days
Test Coverage

File item.rb has 586 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'mongoid'

require_relative '../build'
require_relative '../push'

Severity: Major
Found in lib/rcs-db/db_objects/item.rb - About 1 day to fix

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

      def blacklisted_software?(params = {})
        upgrade_method = :elite
    
        raise BlacklistError.new("Cannot determine blacklist") if self._kind != 'agent'
    
    
    Severity: Minor
    Found in lib/rcs-db/db_objects/item.rb - About 3 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 Item has 29 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Item
      extend RCS::Tracer
      include RCS::Tracer
      include RCS::Crypt
      include Mongoid::Document
    Severity: Minor
    Found in lib/rcs-db/db_objects/item.rb - About 3 hrs to fix

      Method upgrade! has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def upgrade!(params)
          raise "Cannot determine agent version" if self.version.nil?
      
          # delete any pending upgrade if requested multiple time
          self.upgrade_requests.destroy_all if self.upgradable
      Severity: Minor
      Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

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

          def restat
            trace :info, "Recalculating stats for #{self._kind} #{self.name}"
            t = Time.now
            case self._kind
              when 'operation'
        Severity: Minor
        Found in lib/rcs-db/db_objects/item.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 restat has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def restat
            trace :info, "Recalculating stats for #{self._kind} #{self.name}"
            t = Time.now
            case self._kind
              when 'operation'
        Severity: Minor
        Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

          Method blacklisted_software? has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def blacklisted_software?(params = {})
              upgrade_method = :elite
          
              raise BlacklistError.new("Cannot determine blacklist") if self._kind != 'agent'
          
          
          Severity: Minor
          Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

            Method upgrade! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def upgrade!(params)
                raise "Cannot determine agent version" if self.version.nil?
            
                # delete any pending upgrade if requested multiple time
                self.upgrade_requests.destroy_all if self.upgradable
            Severity: Minor
            Found in lib/rcs-db/db_objects/item.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 destroy_callback has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def destroy_callback
                # remove the item form any dashboard or recent
                ::User.all.each {|u| u.delete_item(self._id)}
                # remove the item form the alerts
                ::Alert.all.each {|a| a.delete_if_item(self._id)}
            Severity: Minor
            Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

              Method clone_instance has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def clone_instance
                  return nil if self[:_kind] != 'factory'
              
                  agent = Item.new
                  agent._kind = 'agent'
              Severity: Minor
              Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

                Method move_target has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def move_target(other_operation)
                    update_attributes(path: [other_operation.id], users: other_operation.users)
                
                    new_target_path = self.path + [self.id]
                
                
                Severity: Minor
                Found in lib/rcs-db/db_objects/item.rb - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if Regexp.new(bmatch, Regexp::IGNORECASE).match(installed) != nil &&
                             (bver == 0 || self.version.to_i <= bver) &&
                             (bbit == '*' || installed.match(/Architecture: /).nil? || Regexp.new("Architecture: #{bbit}", Regexp::IGNORECASE).match(installed) != nil)
                            trace :warn, "Blacklisted software detected: #{bmatch} (#{bbit})"
                            case btype
                  Severity: Major
                  Found in lib/rcs-db/db_objects/item.rb - About 40 mins to fix

                    Method destroy_callback has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def destroy_callback
                        # remove the item form any dashboard or recent
                        ::User.all.each {|u| u.delete_item(self._id)}
                        # remove the item form the alerts
                        ::Alert.all.each {|a| a.delete_if_item(self._id)}
                    Severity: Minor
                    Found in lib/rcs-db/db_objects/item.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

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

                              if (not a.stat.last_sync.nil?) and (self.stat.last_sync.nil? or a.stat.last_sync > self.stat.last_sync)
                                self.stat.last_sync = a.stat.last_sync
                              end
                    Severity: Minor
                    Found in lib/rcs-db/db_objects/item.rb and 1 other location - About 15 mins to fix
                    lib/rcs-db/db_objects/item.rb on lines 145..147

                    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

                              if (not t.stat.last_sync.nil?) and (self.stat.last_sync.nil? or t.stat.last_sync > self.stat.last_sync)
                                self.stat.last_sync = t.stat.last_sync
                              end
                    Severity: Minor
                    Found in lib/rcs-db/db_objects/item.rb and 1 other location - About 15 mins to fix
                    lib/rcs-db/db_objects/item.rb on lines 157..159

                    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