dice-cyfronet/atmosphere

View on GitHub

Showing 52 of 52 total issues

Method bill_deployment has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
Open

    def self.bill_deployment(dep, billing_time, message, apply_prepayment = true)
      appl = dep.appliance # Shorthand
      if dep.prepaid_until.blank?
        # This should not happen - it means that we do not know when this deployment will run out of funds.
        # Therefore we cannot meaningfully bill it again and must return an error.
Severity: Minor
Found in app/services/atmosphere/billing_service.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 AppliancesController has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

class Atmosphere::Api::V1::AppliancesController < Atmosphere::Api::ApplicationController
  before_action :build_appliance, only: :create

  load_and_authorize_resource :appliance,
                              class: 'Atmosphere::Appliance'
Severity: Minor
Found in app/controllers/atmosphere/api/v1/appliances_controller.rb - About 3 hrs to fix

    Method execute has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

          def execute
            action.log(I18n.t('satisfy_appliance.start'))
            if appliance.virtual_machines.blank?
              if optimization_strategy.can_reuse_vm? &&
                !(vm = optimization_strategy.vm_to_reuse).nil?
    Severity: Minor
    Found in app/services/atmosphere/cloud/satisfy_appliance.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 nav_link has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def nav_link(options = {}, &block)
          if path = options.delete(:path)
            if path.respond_to?(:each)
              c = path.map { |p| p.split('#').first }
              a = path.map { |p| p.split('#').last }
    Severity: Minor
    Found in app/helpers/atmosphere/nav_helper.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

    Class VmUpdater has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class VmUpdater
        def initialize(tenant, server, updater_class = Proxy::ApplianceProxyUpdater)
          @tenant = tenant
          @server = server
          @updater_class = updater_class
    Severity: Minor
    Found in app/services/atmosphere/vm_updater.rb - About 2 hrs to fix

      Method execute has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def execute
              action.log(I18n.t('satisfy_appliance.start'))
              if appliance.virtual_machines.blank?
                if optimization_strategy.can_reuse_vm? &&
                  !(vm = optimization_strategy.vm_to_reuse).nil?
      Severity: Minor
      Found in app/services/atmosphere/cloud/satisfy_appliance.rb - About 1 hr to fix

        Method action has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def action
            return reboot if reboot_action?
            return scale if scale_action?
            return pause if pause_action?
            return stop if stop_action?
        Severity: Minor
        Found in app/controllers/atmosphere/api/v1/appliances_controller.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 bill_deployment has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def self.bill_deployment(dep, billing_time, message, apply_prepayment = true)
              appl = dep.appliance # Shorthand
              if dep.prepaid_until.blank?
                # This should not happen - it means that we do not know when this deployment will run out of funds.
                # Therefore we cannot meaningfully bill it again and must return an error.
        Severity: Minor
        Found in app/services/atmosphere/billing_service.rb - About 1 hr to fix

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

                  def select
                    best_template = nil
                    best_tenant = nil
                    best_flavor = nil
                    instantiation_cost = Float::INFINITY
          Severity: Minor
          Found in app/providers/atmosphere/optimization_strategy/default.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 perform_update! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def perform_update!
                vmt.id_at_site = image.id
                vmt.name = image.name
                vmt.architecture = image.architecture
                vmt.state = image.status.downcase.to_sym
          Severity: Minor
          Found in app/services/atmosphere/cloud/vmt_updater.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 select has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def select
                    best_template = nil
                    best_tenant = nil
                    best_flavor = nil
                    instantiation_cost = Float::INFINITY
          Severity: Minor
          Found in app/providers/atmosphere/optimization_strategy/default.rb - About 1 hr to fix

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

                    def get_optimal_flavor_for_tenant(tmpl, t)
                      mfs = matching_flavors(tmpl, t)
                      best_cost = Float::INFINITY
                      best_mem = Float::INFINITY
                      opt_fl = nil
            Severity: Minor
            Found in app/providers/atmosphere/optimization_strategy/default.rb - About 1 hr to fix

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

                  def min_elements_by_with_block(arr, &block)
                    min_elements, arr = first_elements_and_residue(arr, &block)
                    return [] if arr.empty? && min_elements.nil?
                    arr.each do |e|
                      current_min_elements_value = yield(min_elements.first)
              Severity: Major
              Found in lib/atmosphere/utils.rb and 1 other location - About 1 hr to fix
              lib/atmosphere/utils.rb on lines 68..82

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

              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

                  def max_elements_by_with_block(arr, &block)
                    max_elements, arr = first_elements_and_residue(arr, &block)
                    return [] if arr.empty? && max_elements.nil?
                    arr.each do |e|
                      current_max_elements_value = yield(max_elements.first)
              Severity: Major
              Found in lib/atmosphere/utils.rb and 1 other location - About 1 hr to fix
              lib/atmosphere/utils.rb on lines 21..35

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

              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

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

                  def execute
                    Atmosphere::ApplianceType.transaction do
                      if vm = appliance && appliance.virtual_machines.first
                        @tmpl = Atmosphere::VirtualMachineTemplate.
                                create_from_vm(vm, params[:name])
              Severity: Minor
              Found in app/services/atmosphere/save_as_service.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 min_elements_by_with_block has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def min_elements_by_with_block(arr, &block)
                    min_elements, arr = first_elements_and_residue(arr, &block)
                    return [] if arr.empty? && min_elements.nil?
                    arr.each do |e|
                      current_min_elements_value = yield(min_elements.first)
              Severity: Minor
              Found in lib/atmosphere/utils.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 get_optimal_flavor_for_tenant has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                      def get_optimal_flavor_for_tenant(tmpl, t)
                        mfs = matching_flavors(tmpl, t)
                        best_cost = Float::INFINITY
                        best_mem = Float::INFINITY
                        opt_fl = nil
              Severity: Minor
              Found in app/providers/atmosphere/optimization_strategy/default.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 index has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                      def index
                        flavors = []
                        cs_id = params[:compute_site_id]
              
                        if optimizer_query?

              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_from_vm has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def self.create_from_vm(virtual_machine, name = virtual_machine.name)
                    name_with_timestamp = "#{name}/#{VirtualMachineTemplate.generate_timestamp}"
                    tmpl_name = VirtualMachineTemplate.sanitize_tmpl_name(name_with_timestamp)
                    t = virtual_machine.tenant
              
              
              Severity: Minor
              Found in app/models/atmosphere/virtual_machine_template.rb - About 1 hr to fix

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

                    def instantiate_vm(tmpl, tenant, flavor, name)
                      server_id = start_vm_on_cloud(tmpl, tenant, flavor, name)
                      vm = VirtualMachine.find_or_initialize_by(
                          id_at_site: server_id,
                          tenant: tenant
                Severity: Minor
                Found in app/services/atmosphere/appliance_vms_manager.rb - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language