dice-cyfronet/atmosphere

View on GitHub

Showing 52 of 52 total issues

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

        def index
          flavors = []
          cs_id = params[:compute_site_id]

          if optimizer_query?

    Method max_elements_by_with_block has a Cognitive Complexity of 9 (exceeds 5 allowed). 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: Minor
    Found in lib/atmosphere/utils.rb - About 55 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 initialize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(user, load_admin_abilities = true, pdp_class = nil)
          @pdp_class = pdp_class
    
          @ability_builders = ability_builder_classes.map do |builder_class|
            builder_class.new(self, user, pdp_class)
    Severity: Minor
    Found in app/models/atmosphere/ability.rb - About 55 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 update has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      def update
        alert = nil
        params[:virtual_machine_flavor][:hourly_cost].each do |os_family_id, cost|
          os_family = Atmosphere::OSFamily.find_by(id: os_family_id)
          if cost.strip.empty? &&
    Severity: Minor
    Found in app/controllers/atmosphere/admin/virtual_machine_flavors_controller.rb - About 55 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 add_dnat_for_vm has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_dnat_for_vm(vm, pmts)
          pmt_map = {}
          to_add = pmts.collect {|pmt|
            if not pmt.target_port.in? MIN_PORT_NO..MAX_PORT_NO
              Rails.logger.error "Error when trying to add redirections for VM #{vm.uuid} with IP #{vm.ip}. Requested redirection for forbidden port #{pmt.target_port}"
    Severity: Minor
    Found in app/services/atmosphere/dnat_wrangler.rb - About 55 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 add_dnat has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_dnat
          return unless ip?
          pmts = nil
          if appliances.first && appliances.first.development?
            pmts = appliances.first.dev_mode_property_set.port_mapping_templates
    Severity: Minor
    Found in app/models/atmosphere/virtual_machine.rb - About 55 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 create_or_update_http_mappings has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def create_or_update_http_mappings
            to_update, to_remove = [], []
            port_mapping_templates.each do |pmt|
              to_update << update_for_pmt(pmt, 'http') if pmt.http?
              to_update << update_for_pmt(pmt, 'https') if pmt.https?
    Severity: Minor
    Found in app/services/atmosphere/proxy/appliance_proxy_updater.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

    Avoid deeply nested control flow statements.
    Open

                    BillingLog.new(timestamp: Time.now.utc, user: appl.appliance_set.user, appliance: appl.id.to_s+'---'+(appl.name.blank? ? 'unnamed_appliance' : appl.name), fund: appl.fund.name, message: "Error saving appliance following update of billing information.", actor: "bill_appliance", amount_billed: 0).save
    Severity: Major
    Found in app/services/atmosphere/billing_service.rb - About 45 mins to fix

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

          def create_dev_mode_property_set(options={})
            unless dev_mode_property_set
              set = DevModePropertySet.create_from(appliance_type)
              set.preference_memory = options[:preference_memory] if options[:preference_memory]
              set.preference_cpu = options[:preference_cpu] if options[:preference_cpu]
      Severity: Minor
      Found in app/models/atmosphere/appliance.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

      Avoid deeply nested control flow statements.
      Open

                      BillingLog.new(timestamp: Time.now.utc, user: appl.appliance_set.user, appliance: appl.id.to_s+'---'+(appl.name.blank? ? 'unnamed_appliance' : appl.name), fund: appl.fund.name, message: message, actor: "bill_appliance", amount_billed: amount_due).save
      Severity: Major
      Found in app/services/atmosphere/billing_service.rb - About 45 mins to fix

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

            def perform_update!
              vm.source_template ||= source_template
              vm.name = server.name || '[unnamed]'
              vm.state = map_saving_state(vm, server.task_state) ||
                map_state(server.state.downcase.to_sym)
        Severity: Minor
        Found in app/services/atmosphere/vm_updater.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

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

            def map_t(t)
              {
                id: t.id,
                site_id: t.tenant_id,
                name: t.name,
        app/serializers/atmosphere/clew_appliance_types_serializer.rb on lines 52..65

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

        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 ensure_single_default has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def ensure_single_default
              unless default
                ufs = UserFund.where(user_id: user_id)
                if ufs.count == 0 || (ufs.count == 1 && ufs[0].id == id)
                  self.default = true
        Severity: Minor
        Found in app/models/atmosphere/user_fund.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

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

            def map_t(t)
              {
                id: t.id,
                site_id: t.tenant_id,
                name: t.name,
        Severity: Minor
        Found in app/serializers/atmosphere/clew_appliance_types_serializer.rb and 1 other location - About 35 mins to fix
        app/serializers/atmosphere/clew_appliance_instances_serializer.rb on lines 95..108

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

        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 get_candidate_tenants_for_template has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

                def get_candidate_tenants_for_template(tmpl)
                  # Determine which tenants can be used to spawn this specific template in the context
                  # of the current @appliance.
                  # If @appliance is nil (which may happen) return active tenants:
                  if @appliance.blank?
        Severity: Minor
        Found in app/providers/atmosphere/optimization_strategy/default.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 update_custom_proxy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_custom_proxy
              old_custom_name = custom_name_was
        
              yield
        
        
        Severity: Minor
        Found in app/models/atmosphere/http_mapping.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

            def min_elements_by_without_block(arr)
              arr.compact!
              return [] if arr.empty?
              min_elements = [arr.shift]
              arr.each do |e|
        Severity: Minor
        Found in lib/atmosphere/utils.rb and 1 other location - About 35 mins to fix
        lib/atmosphere/utils.rb on lines 85..96

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

        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_without_block(arr)
              arr.compact!
              return [] if arr.empty?
              max_elements = [arr.shift]
              arr.each do |e|
        Severity: Minor
        Found in lib/atmosphere/utils.rb and 1 other location - About 35 mins to fix
        lib/atmosphere/utils.rb on lines 54..65

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

        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

        Avoid too many return statements within this method.
        Open

            return start if start_action?
        Severity: Major
        Found in app/controllers/atmosphere/api/v1/appliances_controller.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

              return suspend if suspend_action?
          Severity: Major
          Found in app/controllers/atmosphere/api/v1/appliances_controller.rb - About 30 mins to fix
            Severity
            Category
            Status
            Source
            Language