HewlettPackard/oneview-sdk-ruby

View on GitHub

Showing 225 of 225 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

if @client.api_version.to_i > 200 && @client.api_version.to_i < 600
  scope_1 = scope_class.new(@client, name: 'Scope 1')
  scope_1.create!
  scope_2 = scope_class.new(@client, name: 'Scope 2')
  scope_2.create!
Severity: Major
Found in examples/shared_samples/fcoe_network.rb and 3 other locations - About 1 hr to fix
examples/shared_samples/ethernet_network.rb on lines 104..129
examples/shared_samples/fc_network.rb on lines 75..100
examples/shared_samples/logical_interconnect_group.rb on lines 187..212

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

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

module OneviewSDK
  module API1200
    module Synergy
      # Ethernet network resource implementation for API1200 Synergy
      class EthernetNetwork < OneviewSDK::API1000::Synergy::EthernetNetwork
lib/oneview-sdk/resource/api1200/c7000/ethernet_network.rb on lines 14..30

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

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

module OneviewSDK
  module API1200
    module C7000
      # Ethernet network resource implementation for API1200 C7000
      class EthernetNetwork < OneviewSDK::API1000::C7000::EthernetNetwork
Severity: Major
Found in lib/oneview-sdk/resource/api1200/c7000/ethernet_network.rb and 1 other location - About 1 hr to fix
lib/oneview-sdk/resource/api1200/synergy/ethernet_network.rb on lines 14..30

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

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

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

module OneviewSDK
  module API500
    module C7000
      # Enclosure resource implementation for API500 C7000
      class Enclosure < OneviewSDK::API300::C7000::Enclosure
Severity: Major
Found in lib/oneview-sdk/resource/api500/c7000/enclosure.rb and 1 other location - About 1 hr to fix
lib/oneview-sdk/resource/api500/synergy/enclosure.rb on lines 14..52

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

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

module OneviewSDK
  module API500
    module Synergy
      # Enclosure resource implementation for API500 Synergy
      class Enclosure < OneviewSDK::API300::Synergy::Enclosure
Severity: Major
Found in lib/oneview-sdk/resource/api500/synergy/enclosure.rb and 1 other location - About 1 hr to fix
lib/oneview-sdk/resource/api500/c7000/enclosure.rb on lines 14..52

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

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

            def add_interconnect(bay, type, logical_downlink = nil, enclosure_index = nil)
              enclosure_index ||= type.include?('Virtual Connect SE 16Gb FC Module') ? -1 : 1
              entry = parse_interconnect_map_template(bay, enclosure_index)
              entry['logicalDownlinkUri'] ||= nil # Default value in case of no specified logical downlink
              if logical_downlink

    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

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

          def like?(other)
            if other.is_a? Hash
              other_copy = Marshal.load(Marshal.dump(other))
            else
              other_copy = other.dup
    Severity: Minor
    Found in lib/oneview-sdk/resource/api200/storage_system.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 from_file has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.from_file(client, file_path)
          resource = OneviewSDK::Config.load(file_path)
          klass = self
          if klass == OneviewSDK::Resource && resource['type'] # Use correct resource class by parsing type
            klass = OneviewSDK # Secondary/temp class/module reference
    Severity: Minor
    Found in lib/oneview-sdk/resource.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 retrieve! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def retrieve!
            ip_hostname = self['credentials'][:ip_hostname] || self['credentials']['ip_hostname'] rescue nil
            if ip_hostname
              results = self.class.find_by(@client, credentials: { ip_hostname: ip_hostname })
              if results.size == 1
    Severity: Minor
    Found in lib/oneview-sdk/resource/api200/storage_system.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 retrieve! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def retrieve!
            hostname = @data['hostname'] || @data['mpHostInfo']['mpHostName'] rescue nil
            if hostname
              results = self.class.find_by(@client, 'mpHostInfo' => { 'mpHostName' => hostname })
              if results.size == 1
    Severity: Minor
    Found in lib/oneview-sdk/resource/api200/server_hardware.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 create_volume_with_attachment has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def create_volume_with_attachment(storage_pool, volume_options, attachment_options = {})
            raise IncompleteResource, 'Storage Pool not found!' unless storage_pool.retrieve!
            # Convert symbols keys to string in volume_options and attachment_options
            volume_options = Hash[volume_options.map { |k, v| [k.to_s, v] }]
            attachment_options = Hash[attachment_options.map { |k, v| [k.to_s, v] }]
    Severity: Minor
    Found in lib/oneview-sdk/resource/api200/server_profile.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 upload_file has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def upload_file(file_path, path, options = {}, timeout = READ_TIMEOUT)
          raise NotFound, "ERROR: File '#{file_path}' not found!" unless File.file?(file_path)
          options = Hash[options.map { |k, v| [k.to_s, v] }]
          body_params = options['body'] || {}
          headers_params = options['header'] || {}
    Severity: Minor
    Found in lib/oneview-sdk/rest.rb - About 1 hr to fix

      Method initialize has 32 lines of code (exceeds 25 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 1 hr to fix

        Method create_from_file has 32 lines of code (exceeds 25 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 1 hr to fix

          Method response_handler has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def response_handler(response, wait_on_task = true)
                case response.code.to_i
                when RESPONSE_CODE_OK # Synchronous read/query
                  begin
                    return JSON.parse(response.body)
          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 retrieve! has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def retrieve!
                  raise IncompleteResource, 'Must set resource name or uri before trying to retrieve!' unless @data['name'] || @data['uri']
                  raise IncompleteResource, 'Must set resource storageSystemUri before trying to retrieve!' unless @data['storageSystemUri']
                  results = self.class.find_by(@client, name: @data['name'], storageSystemUri: @data['storageSystemUri']) if @data['name']
                  results = self.class.find_by(@client, uri:  @data['uri'], storageSystemUri: @data['storageSystemUri']) if @data['uri'] &&
          Severity: Minor
          Found in lib/oneview-sdk/resource/api200/storage_pool.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