fog/fog-azure-rm

View on GitHub
lib/fog/azurerm/requests/compute/create_virtual_machine.rb

Summary

Maintainability
D
2 days
Test Coverage
F
12%

File create_virtual_machine.rb has 362 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'base64'

WHITE_SPACE = ' '.freeze

module Fog
Severity: Minor
Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 4 hrs to fix

    Method create_virtual_machine has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def create_virtual_machine(*)
              vm = {
                'location' => 'westus',
                'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/virtualMachines/fog-test-server',
                'name' => 'fog-test-server',
    Severity: Major
    Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 2 hrs to fix

      Method create_virtual_machine has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def create_virtual_machine(vm_config, async = false)
                vm_name = vm_config[:name]
                rg_name = vm_config[:resource_group]
      
                # In case of updating the VM, we check if the user has passed any value for os_disk_name
      Severity: Minor
      Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method get_unmanaged_vm_storage_profile has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def get_unmanaged_vm_storage_profile(vm_config)
                # Arguments unpacking
                vm_name = vm_config[:name]
                storage_account_name = vm_config[:storage_account_name]
                publisher = vm_config[:publisher]
      Severity: Minor
      Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 1 hr to fix

        Method get_managed_vm_storage_profile has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def get_managed_vm_storage_profile(vm_config)
                  # Argument unpacking
                  managed_disk_storage_type = vm_config[:managed_disk_storage_type]
                  vhd_path = vm_config[:vhd_path]
                  resource_group = vm_config[:resource_group]
        Severity: Minor
        Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 1 hr to fix

          Method create_virtual_machine has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def create_virtual_machine(vm_config, async = false)
                    vm_name = vm_config[:name]
                    rg_name = vm_config[:resource_group]
          
                    # In case of updating the VM, we check if the user has passed any value for os_disk_name
          Severity: Minor
          Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 1 hr to fix

            Method copy_vhd_to_storage_account has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
                      # Copy if VHD does not exist belongs to same storage account.
                      vhd_storage_account_name = (vhd_path.split('/')[2]).split('.')[0]
                      if storage_account_name != vhd_storage_account_name
                        if storage_account_name.nil?
            Severity: Minor
            Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 1 hr to fix

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

                      def configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
                        # It will use the os_disk_name provided or it will generate a name for itself if it is nil
                        os_disk.name = os_disk_name.nil? ? "#{vm_name}_os_disk" : os_disk_name
                        os_disk.os_type = platform
                        os_disk.disk_size_gb = os_disk_size unless os_disk_size.nil?
              Severity: Minor
              Found in lib/fog/azurerm/requests/compute/create_virtual_machine.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 configure_os_disk_object has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                      def configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
              Severity: Minor
              Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 45 mins to fix

                Method image_config_params has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        def image_config_params(location, new_vhd_path, platform, resource_group, vm_name)
                Severity: Minor
                Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 35 mins to fix

                  Method copy_vhd_to_storage_account has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                          def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
                  Severity: Minor
                  Found in lib/fog/azurerm/requests/compute/create_virtual_machine.rb - About 35 mins to fix

                    Method copy_vhd_to_storage_account has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
                              # Copy if VHD does not exist belongs to same storage account.
                              vhd_storage_account_name = (vhd_path.split('/')[2]).split('.')[0]
                              if storage_account_name != vhd_storage_account_name
                                if storage_account_name.nil?
                    Severity: Minor
                    Found in lib/fog/azurerm/requests/compute/create_virtual_machine.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 get_os_disk_parameters has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def get_os_disk_parameters(resource_group, virtual_machine_name)
                              os_disk_parameters = {}
                    
                              begin
                                vm = get_virtual_machine(resource_group, virtual_machine_name, false)
                    Severity: Minor
                    Found in lib/fog/azurerm/requests/compute/create_virtual_machine.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 get_unmanaged_vm_storage_profile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def get_unmanaged_vm_storage_profile(vm_config)
                              # Arguments unpacking
                              vm_name = vm_config[:name]
                              storage_account_name = vm_config[:storage_account_name]
                              publisher = vm_config[:publisher]
                    Severity: Minor
                    Found in lib/fog/azurerm/requests/compute/create_virtual_machine.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 get_os_profile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                            def get_os_profile(vm_config)
                              # Arguments unpacking
                              platform = vm_config[:platform]
                              vm_name = vm_config[:name]
                              username = vm_config[:username]
                    Severity: Minor
                    Found in lib/fog/azurerm/requests/compute/create_virtual_machine.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

                    Avoid rescuing without specifying an error class.
                    Open

                              rescue

                    This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

                    Example: EnforcedStyle: implicit

                    # `implicit` will enforce using `rescue` instead of
                    # `rescue StandardError`.
                    
                    # bad
                    begin
                      foo
                    rescue StandardError
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue OtherError
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue StandardError, SecurityError
                      bar
                    end

                    Example: EnforcedStyle: explicit (default)

                    # `explicit` will enforce using `rescue StandardError`
                    # instead of `rescue`.
                    
                    # bad
                    begin
                      foo
                    rescue
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue StandardError
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue OtherError
                      bar
                    end
                    
                    # good
                    begin
                      foo
                    rescue StandardError, SecurityError
                      bar
                    end

                    There are no issues that match your filters.

                    Category
                    Status