ManageIQ/azure-armrest

View on GitHub
lib/azure/armrest/armrest_service.rb

Summary

Maintainability
C
1 day
Test Coverage
C
70%

Class ArmrestService has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

    class ArmrestService
      extend Gem::Deprecate

      # Configuration to access azure APIs
      attr_accessor :armrest_configuration
Severity: Minor
Found in lib/azure/armrest/armrest_service.rb - About 4 hrs to fix

    Method rest_execute has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

            def rest_execute(options, http_method = :get, encode = true, max_retries = 3)
              tries ||= 0
              url = encode ? Addressable::URI.encode(options[:url]) : options[:url]
              options = options.merge(:method => http_method, :url => url)
              RestClient::Request.execute(options)
    Severity: Minor
    Found in lib/azure/armrest/armrest_service.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 rest_execute has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def rest_execute(url, body = nil, http_method = :get, encode = true, max_retries = 3)
    Severity: Minor
    Found in lib/azure/armrest/armrest_service.rb - About 35 mins to fix

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

            def wait(response, max_time = 60, default_interval = 10)
              sleep_time = response.respond_to?(:retry_after) ? response.retry_after.to_i : default_interval
              total_time = 0
      
              until (status = poll(response)) =~ /^succe/i # success or succeeded
      Severity: Minor
      Found in lib/azure/armrest/armrest_service.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 raise_api_exception has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

              def raise_api_exception(err)
                begin
                  content_type_header = err.response.headers[:content_type]
      
                  response = case content_type_header.match(%r{(application/\w+)})[1]
      Severity: Minor
      Found in lib/azure/armrest/armrest_service.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 has too many optional parameters. [4/3]
      Open

            def rest_execute(url, body = nil, http_method = :get, encode = true, max_retries = 3)
              options = {
                :url         => url,
                :proxy       => configuration.proxy,
                :ssl_version => configuration.ssl_version,

      Checks for methods with too many parameters.

      The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters.

      Any number of arguments for initialize method inside a block of Struct.new and Data.define like this is always allowed:

      Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do
        def initialize(one:, two:, three:, four:, five:)
        end
      end

      This is because checking the number of arguments of the initialize method does not make sense.

      NOTE: Explicit block argument &block is not counted to prevent erroneous change that is avoided by making block argument implicit.

      Example: Max: 3

      # good
      def foo(a, b, c = 1)
      end

      Example: Max: 2

      # bad
      def foo(a, b, c = 1)
      end

      Example: CountKeywordArgs: true (default)

      # counts keyword args towards the maximum
      
      # bad (assuming Max is 3)
      def foo(a, b, c, d: 1)
      end
      
      # good (assuming Max is 3)
      def foo(a, b, c: 1)
      end

      Example: CountKeywordArgs: false

      # don't count keyword args towards the maximum
      
      # good (assuming Max is 3)
      def foo(a, b, c, d: 1)
      end

      This cop also checks for the maximum number of optional parameters. This can be configured using the MaxOptionalParameters config option.

      Example: MaxOptionalParameters: 3 (default)

      # good
      def foo(a = 1, b = 2, c = 3)
      end

      Example: MaxOptionalParameters: 2

      # bad
      def foo(a = 1, b = 2, c = 3)
      end

      Avoid more than 3 levels of block nesting.
      Open

                    sleep_time = 5 if sleep_time < 5     # 5 second minimum

      Checks for excessive nesting of conditional and looping constructs.

      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

      The maximum level of nesting allowed is configurable.

      Avoid more than 3 levels of block nesting.
      Open

                    sleep_time = 120 if sleep_time > 120 # 2 minute maximum

      Checks for excessive nesting of conditional and looping constructs.

      You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

      The maximum level of nesting allowed is configurable.

      There are no issues that match your filters.

      Category
      Status