aeolusproject/conductor

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

Summary

Maintainability
F
3 days
Test Coverage

File deployment.rb has 533 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'util/deployable_xml'
require 'util/config_server_util'

class Deployment < ActiveRecord::Base
  acts_as_paranoid
Severity: Major
Found in src/app/models/deployment.rb - About 1 day to fix

    Class Deployment has 54 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Deployment < ActiveRecord::Base
      acts_as_paranoid
    
      include Alberich::PermissionedObject
      class << self
    Severity: Major
    Found in src/app/models/deployment.rb - About 7 hrs to fix

      Method send_launch_requests has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def send_launch_requests(all_inst_match, instance_ids, config_server_id, user_id)
          user = User.find(user_id)
          instances = instance_ids.map{|instance_id| Instance.find(instance_id)}
      
          if config_server_id.nil?
      Severity: Minor
      Found in src/app/models/deployment.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(deployments)
          failed_accounts = {}
          res = []
          deployments.each do |d|
            next unless acc = d.provider_account
      Severity: Minor
      Found in src/app/models/deployment.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 launch! has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def launch!(user)
          self.reload unless self.new_record?
          self.state = STATE_PENDING
          save!
      
      
      Severity: Minor
      Found in src/app/models/deployment.rb - About 1 hr to fix

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

          def uptime_1st_instance
            return nil if events.empty?
        
            first_running = events.find_last_by_status_code(:first_running)
            if instances.deployed.empty?
        Severity: Minor
        Found in src/app/models/deployment.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 launch! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def launch!(user)
            self.reload unless self.new_record?
            self.state = STATE_PENDING
            save!
        
        
        Severity: Minor
        Found in src/app/models/deployment.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 uptime_all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def uptime_all
            return nil if events.empty?
        
            all_running = events.find_last_by_status_code(:all_running)
            some_stopped = events.find_last_by_status_code(:some_stopped)
        Severity: Minor
        Found in src/app/models/deployment.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 end_time has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def end_time
            if events.find_last_by_status_code(:all_running)
              ev = events.find_last_by_status_code(:some_stopped) || events.find_last_by_status_code(:all_stopped)
              ev.present? ? ev.event_time : nil
            else
        Severity: Minor
        Found in src/app/models/deployment.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 handle_completed_rollback has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def handle_completed_rollback
            if self.state_changed? and self.state == STATE_ROLLBACK_COMPLETE
              begin
                if self.events.where(
                    :status_code => 'deployment_launch_match').count > 9
        Severity: Minor
        Found in src/app/models/deployment.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 destroy_deployment_config has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def destroy_deployment_config
            # the implication here is that if there is an instance in this deployment
            # with userdata, then a config server was associated with this deployment;
            # further, the config server associated with one instance is the same config
            # server used for all instances in the deployment
        Severity: Minor
        Found in src/app/models/deployment.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 => "deployments.preset_filters.other_than_stopped", :id => "other_than_stopped", :query => where("deployments.state != ?", "stopped")},
            {:title => "deployments.preset_filters.new", :id => "new", :query => where("deployments.state" => "new")},
            {:title => "deployments.preset_filters.pending", :id => "pending", :query => where("deployments.state" => "pending")},
            {:title => "deployments.preset_filters.running", :id => "running", :query => where("deployments.state" => "running")},
        Severity: Major
        Found in src/app/models/deployment.rb and 1 other location - About 2 hrs to fix
        src/app/models/instance.rb on lines 488..498

        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