HewlettPackard/oneview-sdk-ruby

View on GitHub

Showing 116 of 225 total issues

File cli.rb has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'thor'
require 'json'
require 'yaml'
require 'highline/import'

Severity: Major
Found in lib/oneview-sdk/cli.rb - About 1 day to fix

    Method output has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        def output(data = {}, indent = 0)
          case @options['format']
          when 'json'
            puts JSON.pretty_generate(data)
          when 'yaml'
    Severity: Minor
    Found in lib/oneview-sdk/cli.rb - About 7 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Method recursive_like? has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def recursive_like?(other, data = @data)
          raise "Can't compare with object type: #{other.class}! Must respond_to :each" unless other.respond_to?(:each)
          other.each do |key, val|
            return false unless data && data.respond_to?(:[])
            if val.is_a?(Hash)
    Severity: Minor
    Found in lib/oneview-sdk/resource.rb - About 3 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Class Resource has 31 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Resource
        BASE_URI = '/rest'.freeze
        UNIQUE_IDENTIFIERS = %w[name uri].freeze # Ordered list of unique attributes to search by
        DEFAULT_REQUEST_HEADER = {}.freeze
    
    
    Severity: Minor
    Found in lib/oneview-sdk/resource.rb - About 3 hrs to fix

      Method initialize has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          def initialize(options = {})
            options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
            STDOUT.sync = true
            @logger = options[:logger] || Logger.new(STDOUT)
            %i[debug info warn error level=].each { |m| raise InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
      Severity: Minor
      Found in lib/oneview-sdk/client.rb - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method parse_hash has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_hash(hash, convert_types = false)
            new_hash = {}
            hash.each do |k, v|
              if convert_types
                v = v.to_i if v && v.match(/^\d+$/)
      Severity: Minor
      Found in lib/oneview-sdk/cli.rb - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

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

            def initialize(options = {})
              options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
              STDOUT.sync = true
              @logger = options[:logger] || Logger.new(STDOUT)
              %i[debug info warn error level=].each { |m| raise InvalidClient, "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
      Severity: Minor
      Found in lib/oneview-sdk/image-streamer/client.rb - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method rest has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def rest(method, uri)
            log_level = @options['log_level'] == :warn ? :error : @options['log_level'].to_sym # Default to :error
            client_setup('log_level' => log_level)
            uri_copy = uri.dup
            uri_copy.prepend('/') unless uri_copy.start_with?('/')
      Severity: Minor
      Found in lib/oneview-sdk/cli.rb - About 3 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method client_setup has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def client_setup(client_params = {}, quiet = false, throw_errors = false)
            client_params['ssl_enabled'] = true if @options['ssl_verify'] == true
            client_params['ssl_enabled'] = false if @options['ssl_verify'] == false
            client_params['url'] ||= @options['url'] if @options['url']
            client_params['log_level'] ||= @options['log_level'].to_sym if @options['log_level']
      Severity: Minor
      Found in lib/oneview-sdk/cli.rb - About 2 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Class ServerProfile has 24 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class ServerProfile < Resource
            include OneviewSDK::ResourceHelper::PatchOperation
            BASE_URI = '/rest/server-profiles'.freeze
            UNIQUE_IDENTIFIERS = %w[name uri associatedServer serialNumber serverHardwareUri].freeze
      
      
      Severity: Minor
      Found in lib/oneview-sdk/resource/api200/server_profile.rb - About 2 hrs to fix

        Method parse_type has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def parse_type(type)
              api_ver = (@options['api_version'] || ENV['ONEVIEWSDK_API_VERSION'] || OneviewSDK.api_version).to_i
              unless OneviewSDK::SUPPORTED_API_VERSIONS.include?(api_ver)
                # Find and use the best available match for the desired API version (round down to nearest)
                valid_api_ver = OneviewSDK::SUPPORTED_API_VERSIONS.select { |x| x <= api_ver }.max || OneviewSDK::SUPPORTED_API_VERSIONS.min
        Severity: Minor
        Found in lib/oneview-sdk/cli.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 cert has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

            def cert(type, url = ENV['ONEVIEWSDK_URL'])
              case type.downcase
              when 'check'
                fail_nice 'Must specify a url' unless url
                puts "Checking certificate for '#{url}' ..."
        Severity: Minor
        Found in lib/oneview-sdk/cli.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_from_file has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            def create_from_file(file_path)
              client_setup
              resource = OneviewSDK::Resource.from_file(@client, file_path)
              fail_nice 'Failed to determine resource type!' if resource.class == OneviewSDK::Resource
              existing_resource = resource.class.new(@client, resource.data)
        Severity: Minor
        Found in lib/oneview-sdk/cli.rb - About 2 hrs to fix

        Cognitive Complexity

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

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

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

        Further reading

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

          class Cli < Thor
            # Runner class to enable testing
            class Runner
              def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
                @argv = argv
        Severity: Minor
        Found in lib/oneview-sdk/cli.rb - About 2 hrs to fix

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

                  def retrieve!
                    data_temp = JSON.parse(@data.to_json)
                    serial_number = data_temp['deviceSpecificAttributes']['serialNumber'] rescue nil
                    wwn = data_temp['deviceSpecificAttributes']['wwn'] rescue nil
          
          
          Severity: Minor
          Found in lib/oneview-sdk/resource/api500/c7000/storage_system.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 select_attributes has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              def select_attributes(attributes, data = {})
                attributes = attributes.split(',').map(&:strip).reject(&:empty?).map { |a| a.split('.') } if attributes.is_a?(String)
                r_data = data.is_a?(Hash) ? data : data.data
                temp = {}
                attributes.each do |attr|
          Severity: Minor
          Found in lib/oneview-sdk/cli.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 wait_for has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def wait_for(task_uri)
                raise ArgumentError, 'Must specify a task_uri!' if task_uri.nil? || task_uri.empty?
                loop do
                  task_uri.gsub!(%r{https:(.*)\/rest}, '/rest')
                  task = rest_get(task_uri)
          Severity: Minor
          Found in lib/oneview-sdk/client.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 generate_logical_switch_credentials has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def generate_logical_switch_credentials
                  credentials = []
                  @logical_switch_credentials.each_value do |switch|
                    switch_credentials = []
                    switch_credentials << {
          Severity: Minor
          Found in lib/oneview-sdk/resource/api200/logical_switch.rb - About 1 hr to fix

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

                def build_request(type, uri, options, api_ver)
                  case type.downcase.to_sym
                  when :get
                    request = Net::HTTP::Get.new(uri.request_uri)
                  when :post
            Severity: Minor
            Found in lib/oneview-sdk/rest.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_lig_to_bay has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                    def add_lig_to_bay(bay, lig, enclosureIndex)
                      @data['interconnectBayMappings'].each do |location|
                        next unless location['interconnectBay'] == bay
                        if enclosureIndex
                          next unless location['enclosureIndex'] == enclosureIndex
            Severity: Minor
            Found in lib/oneview-sdk/resource/api300/c7000/enclosure_group.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

            Severity
            Category
            Status
            Source
            Language