theforeman/foreman_fog_proxmox

View on GitHub

Showing 51 of 51 total issues

Class Proxmox has 24 methods (exceeds 20 allowed). Consider refactoring.
Open
  • Open
  • Confirmed
  • Invalid
  • Wontfix
Cancel

  class Proxmox < ComputeResource
    include ProxmoxVmHelper
    include ProxmoxConnection
    include ProxmoxVmNew
    include ProxmoxVmCommands
Severity: Minor
Found in app/models/foreman_fog_proxmox/proxmox.rb - About 2 hrs to fix

    Method update_volume has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open
    • Open
    • Confirmed
    • Invalid
    • Wontfix
    Cancel

        def update_volume(vm, disk, volume_attributes)
          id = disk.id
          if volume_type?(volume_attributes, 'cdrom')
            update_cdrom(vm, disk, volume_attributes)
          elsif volume_type?(volume_attributes, 'hard_disk')
    Severity: Minor
    Found in app/models/foreman_fog_proxmox/proxmox_volumes.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

    Method setVmDetails has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open
    • Open
    • Confirmed
    • Invalid
    • Wontfix
    Cancel

          def setVmDetails
            attrs = compute_resource.provided_attributes
            result = true
            attrs.each do |foreman_attr, fog_attr|
              if foreman_attr == :mac
    Severity: Minor
    Found in app/models/concerns/orchestration/proxmox/compute.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

    Method create_vm has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open
    • Open
    • Confirmed
    • Invalid
    • Wontfix
    Cancel

        def create_vm(args = {})
          vmid = args[:vmid].to_i
          type = args[:type]
          node = client.nodes.get(args[:node_id])
          vmid = node.servers.next_id.to_i if vmid < 1
    Severity: Minor
    Found in app/models/foreman_fog_proxmox/proxmox_vm_commands.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 parse_server_cloudinit has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open
    • Open
    • Confirmed
    • Invalid
    • Wontfix
    Cancel

      def parse_server_cloudinit(args)
        cloudinit_h = {}
        cloudinit = args['cloudinit']
        unless ['none'].include? cloudinit
          volid = args['volid']
    Severity: Minor
    Found in app/helpers/proxmox_vm_cloudinit_helper.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

    Function updateOptions has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open
    • Open
    • Confirmed
    • Invalid
    • Wontfix
    Cancel

    function updateOptions(options_path, start_options_id, end_options_id, start_second_options_id, end_second_options_id, option_id, node_id, second_id) {
      
      var select_ids = selectIds(start_options_id, end_options_id);
      var select_second_ids;
      if ( start_second_options_id != undefined && end_second_options_id != undefined) {
    Severity: Minor
    Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js - About 1 hr to fix

      Method host_interfaces_attrs has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

          def host_interfaces_attrs(host)
            host.interfaces.select(&:physical?).each.with_index.reduce({}) do |hash, (nic, index)|
              set_nic_identifier(nic, index)
              set_container_interface_name(host, nic, index) if container?(host)
              ForemanFogProxmox::HashCollection.remove_empty_values(nic.compute_attributes)
      Severity: Minor
      Found in app/models/foreman_fog_proxmox/proxmox_interfaces.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

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

      function getIndex(item) {
        var index_id = $(item).attr('id');
        var pattern = /(host_compute_attributes_volumes_attributes_||compute_attribute_vm_attrs_volumes_attributes_)(\d+)[_](.*)/i;
        pattern_a = pattern.exec(index_id);
        var index = pattern_a[2];
      app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js on lines 26..32

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

      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
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

      function toggleAccordion(selected){
        ['qemu', 'lxc'].forEach(function(type){
          fieldsets(type).forEach(function(fieldsetId){
            toggleConfigOptions(fieldsetId, selected, type);
          });
      Severity: Major
      Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js and 1 other location - About 1 hr to fix
      app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js on lines 118..124

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

      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
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

      function toggleVolumes(selected){
         ['qemu', 'lxc'].forEach(function(type){
          volumes(type).forEach(function(volume_id){
            toggleVolume(volume_id, selected, type);
          });
      Severity: Major
      Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js and 1 other location - About 1 hr to fix
      app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js on lines 163..169

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

      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

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

      function getIndex(item) {
        var index_id = $(item).attr('id');
        var pattern = /(host_compute_attributes_volumes_attributes_||compute_attribute_vm_attrs_volumes_attributes_)(\d+)[_](.*)/i;
        pattern_a = pattern.exec(index_id);
        var index = pattern_a[2];
      app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js on lines 18..24

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

      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 proxmox_cpus_map has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open
      • Open
      • Confirmed
      • Invalid
      • Wontfix
      Cancel

        def proxmox_cpus_map
          [OpenStruct.new(id: '486', name: '486'),
           OpenStruct.new(id: 'athlon', name: 'athlon'),
           OpenStruct.new(id: 'core2duo', name: 'core2duo'),
           OpenStruct.new(id: 'coreduo', name: 'coreduo'),
      Severity: Minor
      Found in app/helpers/proxmox_compute_selectors_helper.rb - About 1 hr to fix

        Function updateOptions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open
        • Open
        • Confirmed
        • Invalid
        • Wontfix
        Cancel

        function updateOptions(options_path, start_options_id, end_options_id, start_second_options_id, end_second_options_id, option_id, node_id, second_id) {
          
          var select_ids = selectIds(start_options_id, end_options_id);
          var select_second_ids;
          if ( start_second_options_id != undefined && end_second_options_id != undefined) {
        Severity: Minor
        Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js - 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 new_typed_vm has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open
        • Open
        • Confirmed
        • Invalid
        • Wontfix
        Cancel

            def new_typed_vm(new_attr, type)
              convert_config_attributes(new_attr) if new_attr.key?(:config_attributes)
              node_id = new_attr['node_id']
              node = node_id ? client.nodes.get(node_id) : default_node
              new_attr_type = new_attr['type']
        Severity: Minor
        Found in app/models/foreman_fog_proxmox/proxmox_vm_new.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 password_proxmox_f has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open
        • Open
        • Confirmed
        • Invalid
        • Wontfix
        Cancel

          def password_proxmox_f(f, attr, options = {})
            unset_button = options.delete(:unset)
            value = f.object[attr] if options.delete(:keep_value)
            password_field_tag(:fakepassword, value, :style => 'display: none', :autocomplete => 'new-password-fake') +
              field(f, attr, options) do
        Severity: Minor
        Found in app/helpers/proxmox_form_helper.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 add_or_delete_typed_interface has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open
        • Open
        • Confirmed
        • Invalid
        • Wontfix
        Cancel

          def add_or_delete_typed_interface(interface_attributes, interfaces_to_delete, interfaces_to_add, type)
            logger.debug("add_or_delete_typed_interface(#{type}): interface_attributes=#{interface_attributes}")
            ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes)
            if interface_attributes['compute_attributes']
              ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes['compute_attributes'])
        Severity: Minor
        Found in app/helpers/proxmox_vm_interfaces_helper.rb - About 1 hr to fix

          Function updateOptions has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open
          • Open
          • Confirmed
          • Invalid
          • Wontfix
          Cancel

          function updateOptions(options_path, start_options_id, end_options_id, start_second_options_id, end_second_options_id, option_id, node_id, second_id) {
          Severity: Major
          Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js - About 1 hr to fix

            Method parse_hard_disk_volume has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

              def parse_hard_disk_volume(args)
                logger.debug(format(_('parse_hard_disk_volume(): args=%<args>s'), args: args))
                disk = {}
                disk[:id] = args['id'] if args.key?('id')
                disk[:volid] = args['volid'] if args.key?('volid')
            Severity: Minor
            Found in app/helpers/proxmox_vm_volumes_helper.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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

              def proxmox_scsihw_map
                [OpenStruct.new(id: 'lsi', name: 'lsi'),
                 OpenStruct.new(id: 'lsi53c810', name: 'lsi53c810'),
                 OpenStruct.new(id: 'megasas', name: 'megasas'),
                 OpenStruct.new(id: 'virtio-scsi-pci', name: 'virtio-scsi-pci'),
            Severity: Minor
            Found in app/helpers/proxmox_compute_selectors_helper.rb and 1 other location - About 55 mins to fix
            app/helpers/proxmox_compute_controllers_helper.rb on lines 32..38

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

            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
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

              def proxmox_scsi_controllers_map
                [OpenStruct.new(id: 'lsi', name: 'LSI 53C895A (Default)'),
                 OpenStruct.new(id: 'lsi53c810', name: 'LSI 53C810'),
                 OpenStruct.new(id: 'virtio-scsi-pci', name: 'VirtIO SCSI'),
                 OpenStruct.new(id: 'virtio-scsi-single', name: 'VirtIO SCSI Single'),
            Severity: Minor
            Found in app/helpers/proxmox_compute_controllers_helper.rb and 1 other location - About 55 mins to fix
            app/helpers/proxmox_compute_selectors_helper.rb on lines 126..132

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

            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 extract_id has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def extract_id(vm, volume_attributes)
                  id = ''
                  if volume_exists?(vm, volume_attributes)
                    id = volume_attributes['id']
                  else
            Severity: Minor
            Found in app/models/foreman_fog_proxmox/proxmox_volumes.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

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def client
                  @client ||= ::Fog::Proxmox::Compute.new(fog_credentials)
                rescue Excon::Errors::Unauthorized => e
                  raise ::Foreman::Exception, 'User token expired' if token_expired?(e)
                rescue StandardError => e
            Severity: Major
            Found in app/models/foreman_fog_proxmox/proxmox.rb and 2 other locations - About 45 mins to fix
            app/models/foreman_fog_proxmox/proxmox.rb on lines 160..167
            app/models/foreman_fog_proxmox/proxmox.rb on lines 169..176

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

            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 save_volume has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def save_volume(vm, volume_attributes)
                  logger.debug("save_volume(#{vm.identity}) volume_attributes=#{volume_attributes}")
                  id = extract_id(vm, volume_attributes)
                  if volume_exists?(vm, volume_attributes)
                    if volume_to_delete?(volume_attributes)
            Severity: Minor
            Found in app/models/foreman_fog_proxmox/proxmox_volumes.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

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def network_client
                  @network_client ||= ::Fog::Proxmox::Network.new(fog_credentials)
                rescue Excon::Errors::Unauthorized => e
                  raise ::Foreman::Exception, 'User token expired' if token_expired?(e)
                rescue StandardError => e
            Severity: Major
            Found in app/models/foreman_fog_proxmox/proxmox.rb and 2 other locations - About 45 mins to fix
            app/models/foreman_fog_proxmox/proxmox.rb on lines 151..158
            app/models/foreman_fog_proxmox/proxmox.rb on lines 160..167

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

            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 version has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def version
                  v = identity_client.read_version if identity_client
                  v ? v['version'] : 'Unknown'
                rescue ::Foreman::Exception => e
                  return 'Unkown' if e.message == 'User token expired'
            Severity: Minor
            Found in app/models/foreman_fog_proxmox/proxmox_version.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

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def identity_client
                  @identity_client ||= ::Fog::Proxmox::Identity.new(fog_credentials)
                rescue Excon::Errors::Unauthorized => e
                  raise ::Foreman::Exception, 'User token expired' if token_expired?(e)
                rescue StandardError => e
            Severity: Major
            Found in app/models/foreman_fog_proxmox/proxmox.rb and 2 other locations - About 45 mins to fix
            app/models/foreman_fog_proxmox/proxmox.rb on lines 151..158
            app/models/foreman_fog_proxmox/proxmox.rb on lines 169..176

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

            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 volume_type? has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

              def volume_type?(args, type)
                if args.key?('storage_type')
                  args['storage_type'] == type
                else
                  Fog::Proxmox::DiskHelper.cloud_init?(args['volid']) if type == 'cloud_init'
            Severity: Minor
            Found in app/helpers/proxmox_vm_volumes_helper.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 save_vm has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def save_vm(uuid, new_attributes)
                  vm = find_vm_by_uuid(uuid)
                  templated = new_attributes['templated']
                  node_id = new_attributes['node_id']
                  if templated == '1' && !vm.templated?
            Severity: Minor
            Found in app/models/foreman_fog_proxmox/proxmox_vm_commands.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

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                  def >(other)
                    raise TypeError unless other.is_a?(SemverClass)
            
                    result = @major > other.major
                    result = @minor > other.minor if @major == other.major
            Severity: Major
            Found in lib/foreman_fog_proxmox/semver.rb and 3 other locations - About 45 mins to fix
            lib/foreman_fog_proxmox/semver.rb on lines 39..45
            lib/foreman_fog_proxmox/semver.rb on lines 48..54
            lib/foreman_fog_proxmox/semver.rb on lines 66..72

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

            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 4 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                  def <(other)
                    raise TypeError unless other.is_a?(SemverClass)
            
                    result = @major < other.major
                    result = @minor < other.minor if @major == other.major
            Severity: Major
            Found in lib/foreman_fog_proxmox/semver.rb and 3 other locations - About 45 mins to fix
            lib/foreman_fog_proxmox/semver.rb on lines 39..45
            lib/foreman_fog_proxmox/semver.rb on lines 57..63
            lib/foreman_fog_proxmox/semver.rb on lines 66..72

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

            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 4 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                  def >=(other)
                    raise TypeError unless other.is_a?(SemverClass)
            
                    result = @major >= other.major
                    result = @minor >= other.minor if @major == other.major
            Severity: Major
            Found in lib/foreman_fog_proxmox/semver.rb and 3 other locations - About 45 mins to fix
            lib/foreman_fog_proxmox/semver.rb on lines 39..45
            lib/foreman_fog_proxmox/semver.rb on lines 48..54
            lib/foreman_fog_proxmox/semver.rb on lines 57..63

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

            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 4 locations. Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                  def <=(other)
                    raise TypeError unless other.is_a?(SemverClass)
            
                    result = @major <= other.major
                    result = @minor <= other.minor if @major == other.major
            Severity: Major
            Found in lib/foreman_fog_proxmox/semver.rb and 3 other locations - About 45 mins to fix
            lib/foreman_fog_proxmox/semver.rb on lines 48..54
            lib/foreman_fog_proxmox/semver.rb on lines 57..63
            lib/foreman_fog_proxmox/semver.rb on lines 66..72

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

            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 add_and_format_element has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open
            • Open
            • Confirmed
            • Invalid
            • Wontfix
            Cancel

                def self.add_and_format_element(dest, dest_key, origin, origin_key, format = :to_s)
            Severity: Minor
            Found in lib/foreman_fog_proxmox/hash_collection.rb - About 35 mins to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  case 'lxc':
                    updateOptions('ostemplates', 'compute_attributes_ostemplate', 'storage', 'compute_attributes_ostemplate', 'file', 'storage', node_id, undefined);
                    updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id, undefined);
                    updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id, undefined);
                    break;
              Severity: Minor
              Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js and 1 other location - About 35 mins to fix
              app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js on lines 202..206

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

              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
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  case 'qemu':
                    updateOptions('isostorages', 'compute_attributes_config_attributes', 'cdrom_storage', 'compute_attributes_config_attributes', 'cdrom_iso', 'storage', node_id, undefined);
                    updateOptions('storages', 'compute_attributes_volumes_attributes', 'storage', undefined, undefined, 'storage', node_id, undefined);
                    updateOptions('bridges', 'interfaces_attributes', 'compute_attributes_bridge', undefined, undefined, 'iface', node_id, undefined);
                    break;
              Severity: Minor
              Found in app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js and 1 other location - About 35 mins to fix
              app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js on lines 207..211

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

              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 check_cidr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def check_cidr(nic_compute_attributes, v6, ip)
                    valid = Fog::Proxmox::IpHelper.send(cidr_prefix_method(v6), cidr_prefix(nic_compute_attributes, v6))
                    ipv = "IPv#{v6 ? '6' : '4'}"
                    max = v6 ? 128 : 32
                    checked = valid || ForemanFogProxmox::Value.empty?(ip)
              Severity: Minor
              Found in app/models/foreman_fog_proxmox/proxmox_interfaces.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 set_ip has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def set_ip(host, nic, nic_compute_attributes, v6 = false)
                    ip = nic.send(ip_s(v6).to_sym)
                    if container?(host)
                      if dhcp?(nic_compute_attributes, v6)
                        ip = 'dhcp'
              Severity: Minor
              Found in app/models/foreman_fog_proxmox/proxmox_interfaces.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 each has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                    def each(collection_filters = {}, &block)
                      if block_given?
                        Kernel.loop do
                          break unless collection_filters[:marker]
              
              
              Severity: Minor
              Found in app/models/concerns/fog_extensions/proxmox/node.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 parsed_typed_volumes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def parsed_typed_volumes(args, type, parsed_vm)
                  logger.debug("parsed_typed_volumes(#{type}): args=#{args}")
                  volumes_attributes = args['volumes_attributes']
                  unless ForemanFogProxmox::Value.empty?(args['config_attributes'])
                    volumes_attributes ||= args['config_attributes']['volumes_attributes']
              Severity: Minor
              Found in app/helpers/proxmox_vm_volumes_helper.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 cluster_nodes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def cluster_nodes(compute_resource)
                  nodes = compute_resource.nodes ? compute_resource.nodes.collect(&:node) : []
                rescue ::Foreman::Exception => e
                  return [] if e.message == 'User token expired'
                rescue StandardError => e
              Severity: Minor
              Found in app/helpers/proxmox_compute_resources_helper.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 compute_dhcps has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def compute_dhcps(interface_attributes_h)
                  interface_attributes_h[:dhcp] = interface_attributes_h[:ip] == 'dhcp' ? '1' : '0'
                  interface_attributes_h[:ip] = '' if interface_attributes_h[:dhcp] == '1'
                  interface_attributes_h[:dhcp6] = interface_attributes_h[:ip6] == 'dhcp' ? '1' : '0'
                  interface_attributes_h[:ip6] = '' if interface_attributes_h[:dhcp6] == '1'
              Severity: Minor
              Found in app/helpers/proxmox_vm_interfaces_helper.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 parse_server_cdrom has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def parse_server_cdrom(args)
                  cdrom_media = args['cdrom'] if args.key?('cdrom')
                  cdrom_image = args['volid'] if args.key?('volid')
                  volid = cdrom_image.empty? ? cdrom_media : cdrom_image
                  return {} unless volid
              Severity: Minor
              Found in app/helpers/proxmox_vm_cdrom_helper.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 vm_compute_attributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def vm_compute_attributes(vm)
                    vm_attrs = {}
                    vm_attrs = vm_attrs.merge(vmid: vm.identity, node_id: vm.node_id, type: vm.type)
                    if vm.respond_to?(:config)
                      if vm.config.respond_to?(:disks)
              Severity: Minor
              Found in app/models/foreman_fog_proxmox/proxmox_compute_attributes.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 find_vm_in_servers_by_vmid has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def find_vm_in_servers_by_vmid(servers, vmid)
                    vm = servers.get(vmid) unless ForemanFogProxmox::Value.empty?(vmid)
                    pool_owner(vm) if vm
                    vm
                  rescue Fog::Errors::NotFound
              Severity: Minor
              Found in app/models/foreman_fog_proxmox/proxmox_vm_queries.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 parse_cloudinit_config has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def parse_cloudinit_config(args)
                  filenames = ["meta-data"]
                  config_data = ["instance-id: #{args[:name]}"]
                  user_data = args.delete(:user_data)
                  return args if user_data == ''
              Severity: Minor
              Found in app/helpers/proxmox_vm_cloudinit_helper.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 add_or_delete_typed_interface has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def add_or_delete_typed_interface(interface_attributes, interfaces_to_delete, interfaces_to_add, type)
                  logger.debug("add_or_delete_typed_interface(#{type}): interface_attributes=#{interface_attributes}")
                  ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes)
                  if interface_attributes['compute_attributes']
                    ForemanFogProxmox::HashCollection.remove_empty_values(interface_attributes['compute_attributes'])
              Severity: Minor
              Found in app/helpers/proxmox_vm_interfaces_helper.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 parse_typed_volume has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                def parse_typed_volume(args, type)
                  logger.debug("parse_typed_volume(#{type}): args=#{args}")
                  disk = parse_hard_disk_volume(args) if volume_type?(args,
                    'hard_disk') || volume_type?(args, 'mp') || volume_type?(args, 'rootfs')
                  disk = parse_server_cloudinit(args) if volume_type?(args, 'cloud_init')
              Severity: Minor
              Found in app/helpers/proxmox_vm_volumes_helper.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 to_semver has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def self.to_semver(version)
                    raise ArgumentError unless semver?(version)
              
                    version_a = version.scan(SEMVER_REGEX)
                    raise ArgumentError if version_a.empty?
              Severity: Minor
              Found in lib/foreman_fog_proxmox/semver.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 3 locations. Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def isos_by_id_and_node_and_storage
                    volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id],
                      params[:storage], 'iso')
                    respond_to do |format|
                      format.json { render :json => volumes }
              app/controllers/foreman_fog_proxmox/compute_resources_controller.rb on lines 32..36
              app/controllers/foreman_fog_proxmox/compute_resources_controller.rb on lines 41..45

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

              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 3 locations. Consider refactoring.
              Open
              • Open
              • Confirmed
              • Invalid
              • Wontfix
              Cancel

                  def ostemplates_by_id_and_node_and_storage
                    volumes = load_compute_resource(params[:compute_resource_id]).images_by_storage(params[:node_id],
                      params[:storage], 'vztmpl')
                    respond_to do |format|
                      format.json { render :json => volumes }
              app/controllers/foreman_fog_proxmox/compute_resources_controller.rb on lines 23..27
              app/controllers/foreman_fog_proxmox/compute_resources_controller.rb on lines 41..45

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

              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

              Severity
              Category