aeolusproject/conductor

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

Summary

Maintainability
C
1 day
Test Coverage

Method after_update has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def after_update(instance)
    # This can get stale, so reload it -- if it exists
    instance.deployment.reload if instance.deployment
    if instance.state_changed?
      event = Event.new(:source => instance, :event_time => DateTime.now,
Severity: Minor
Found in src/app/models/instance_observer.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

Method update_quota has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

  def update_quota(state_from, state_to, an_instance)
    pool = an_instance.pool
    pool_family = pool.pool_family
    user = an_instance.owner
    provider_account = an_instance.provider_account
Severity: Minor
Found in src/app/models/instance_observer.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

Method after_update has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def after_update(instance)
    # This can get stale, so reload it -- if it exists
    instance.deployment.reload if instance.deployment
    if instance.state_changed?
      event = Event.new(:source => instance, :event_time => DateTime.now,
Severity: Minor
Found in src/app/models/instance_observer.rb - About 1 hr to fix

    Method update_quota has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def update_quota(state_from, state_to, an_instance)
        pool = an_instance.pool
        pool_family = pool.pool_family
        user = an_instance.owner
        provider_account = an_instance.provider_account
    Severity: Minor
    Found in src/app/models/instance_observer.rb - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                event4 = Event.new(:source => instance.deployment, :event_time => DateTime.now,
                                   :status_code => "some_stopped", :summary => "Some instances are stopped",
                                   :change_hash => instance.changes) if instance.deployment.events.lifetime.last{|e|e.status_code == :all_running}
      Severity: Major
      Found in src/app/models/instance_observer.rb - About 45 mins to fix

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

          def after_save(instance)
            if instance.state_changed? and instance.state == Instance::STATE_STOPPED
              instance.instance_key.destroy if instance.instance_key
        
              if instance.deployment and
        Severity: Minor
        Found in src/app/models/instance_observer.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