aeolusproject/conductor

View on GitHub
src/app/models/instance.rb

Summary

Maintainability
D
2 days
Test Coverage

Class Instance has 50 methods (exceeds 20 allowed). Consider refactoring.
Open

class Instance < ActiveRecord::Base
  acts_as_paranoid

  class << self
    include CommonFilterMethods
Severity: Minor
Found in src/app/models/instance.rb - About 7 hrs to fix

    File instance.rb has 390 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'util/deployable_xml'
    require 'util/instance_config_xml'
    
    class Instance < ActiveRecord::Base
      acts_as_paranoid
    Severity: Minor
    Found in src/app/models/instance.rb - About 5 hrs to fix

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

        def total_state_time(state)
      
          if !STATES.include?(state)
            return _('Error, could not calculate state time: invalid state')
          end
      Severity: Minor
      Found in src/app/models/instance.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 stoppable_inaccessible_instances has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.stoppable_inaccessible_instances(instances)
          failed_accounts = {}
          instances.select do |i|
            next unless STOPPABLE_INACCESSIBLE_STATES.include?(i.state)
            next unless i.provider_account
      Severity: Minor
      Found in src/app/models/instance.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 total_state_time has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def total_state_time(state)
      
          if !STATES.include?(state)
            return _('Error, could not calculate state time: invalid state')
          end
      Severity: Minor
      Found in src/app/models/instance.rb - About 1 hr to fix

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

          def self.csv_export(instances)
            csvm = get_csv_class
            csv_string = csvm.generate(:col_sep => ";", :row_sep => "\r\n") do |csv|
              event_attributes = Event.new.attributes.keys.reject {|key| key if key == "created_at" || key == "updated_at"}
        
        
        Severity: Minor
        Found in src/app/models/instance.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 _('Error, could not calculate state time: state is not monitored')
        Severity: Major
        Found in src/app/models/instance.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                    return acc_stopped_time
          Severity: Major
          Found in src/app/models/instance.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return acc_stopped_time + (Time.now - time_last_stopped)
            Severity: Major
            Found in src/app/models/instance.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                        return acc_shutting_down_time + (Time.now - time_last_shutting_down)
              Severity: Major
              Found in src/app/models/instance.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                          return acc_running_time
                Severity: Major
                Found in src/app/models/instance.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                            return acc_shutting_down_time
                  Severity: Major
                  Found in src/app/models/instance.rb - About 30 mins to fix

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

                      def create_auth_key
                        raise "instance provider_account is not set" unless self.provider_account
                        client = self.provider_account.connect
                        return nil unless client && client.feature?(:instances, :authentication_key)
                        if key = client.create_key(:name => key_name)
                    Severity: Minor
                    Found in src/app/models/instance.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

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

                      PRESET_FILTERS_OPTIONS = [
                        {:title => "instances.preset_filters.other_than_stopped", :id => "other_than_stopped", :query => where("instances.state != ?", "stopped")},
                        {:title => "instances.preset_filters.new", :id => "new", :query => where("instances.state" => "new")},
                        {:title => "instances.preset_filters.pending", :id => "pending", :query => where("instances.state" => "pending")},
                        {:title => "instances.preset_filters.running", :id => "running", :query => where("instances.state" => "running")},
                    Severity: Major
                    Found in src/app/models/instance.rb and 1 other location - About 2 hrs to fix
                    src/app/models/deployment.rb on lines 481..491

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

                    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