cloudfoundry-community/cyoi

View on GitHub

Showing 37 of 37 total issues

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

class Cyoi::Cli::KeyPair::KeyPairCliOpenstack
  attr_reader :provider_client
  attr_reader :attributes
  attr_reader :hl

Severity: Major
Found in lib/cyoi/cli/provider_key_pair/key_pair_openstack.rb and 1 other location - About 2 hrs to fix
lib/cyoi/cli/provider_key_pair/key_pair_aws.rb on lines 2..51

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

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

class Cyoi::Cli::KeyPair::KeyPairCliAws
  attr_reader :provider_client
  attr_reader :attributes
  attr_reader :hl

Severity: Major
Found in lib/cyoi/cli/provider_key_pair/key_pair_aws.rb and 1 other location - About 2 hrs to fix
lib/cyoi/cli/provider_key_pair/key_pair_openstack.rb on lines 2..51

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

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

Class AwsProviderClient has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class Cyoi::Providers::Clients::AwsProviderClient < Cyoi::Providers::Clients::FogProviderClient
  include Cyoi::Providers::Constants::AwsConstants

  # Creates a bucket and makes it publicly read-only
  def create_blobstore(blobstore_name)
Severity: Minor
Found in lib/cyoi/providers/clients/aws_provider_client.rb - About 2 hrs to fix

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

      def create_security_group(security_group_name, description, defns, extra_attributes={})
        security_groups = fog_compute.security_groups
        sg = security_groups.find do |s|
          if extra_attributes[:vpc_id]
            s.name == security_group_name && s.vpc_id == extra_attributes[:vpc_id]
    Severity: Minor
    Found in lib/cyoi/providers/clients/fog_provider_client.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 setup_vcenter has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      def setup_vcenter
        puts "\n"
        attributes.set_default("datacenter", {})
        datacenter = attributes.datacenter
        datacenter["name"] = hl.ask("Datacenter: ").to_s unless datacenter.exists?("name")
    Severity: Minor
    Found in lib/cyoi/cli/providers/provider_cli_vsphere.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_security_group has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create_security_group(security_group_name, description, defns, extra_attributes={})
        security_groups = fog_compute.security_groups
        sg = security_groups.find do |s|
          if extra_attributes[:vpc_id]
            s.name == security_group_name && s.vpc_id == extra_attributes[:vpc_id]
    Severity: Minor
    Found in lib/cyoi/providers/clients/fog_provider_client.rb - About 1 hr to fix

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

        def bootstrap(new_attributes = {})
          new_attributes[:image_id] ||= trusty_image_id(fog_compute.region)
          vpc = new_attributes[:subnet_id]
      
          server = fog_compute.servers.new(new_attributes)
      Severity: Minor
      Found in lib/cyoi/providers/clients/aws_provider_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 setup_credentials has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def setup_credentials
          attributes.set_default("credentials", {})
          credentials = attributes.credentials
          credentials["openstack_username"] = hl.ask("Username: ").to_s unless credentials.exists?("openstack_username")
          credentials["openstack_api_key"] = (hl.ask("Password (API Key): ") { |q| q.echo = 'x' }).to_s unless credentials.exists?("openstack_api_key")
      Severity: Minor
      Found in lib/cyoi/cli/providers/provider_cli_openstack.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 auto_detection_choices has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def auto_detection_choices
          fog_choices = {}
          # Prepare menu options:
          # each provider/profile name gets a menu choice option
          fog_config.inject({}) do |iaas_options, fog_profile|
      Severity: Minor
      Found in lib/cyoi/cli/auto_detection/auto_detection_fog.rb - About 1 hr to fix

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

          def extract_port_definition(port_defn)
            protocol = "tcp"
            ip_range = "0.0.0.0/0"
            if port_defn.is_a? Integer
              port_range = (port_defn..port_defn)
        Severity: Minor
        Found in lib/cyoi/providers/clients/fog_provider_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 bootstrap has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def bootstrap(new_attributes = {})
            new_attributes[:image_id] ||= trusty_image_id(fog_compute.region)
            vpc = new_attributes[:subnet_id]
        
            server = fog_compute.servers.new(new_attributes)
        Severity: Minor
        Found in lib/cyoi/providers/clients/aws_provider_client.rb - About 1 hr to fix

          Method perform_and_return_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def perform_and_return_attributes
              unless valid_address?
                if networks?
                  if vpc = select_vpc
                    subnet = select_subnet_for_vpc(vpc)
          Severity: Minor
          Found in lib/cyoi/cli/provider_addresses/address_cli_aws.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 trusty_image_id has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def trusty_image_id(region=nil)
              region = fog_compute.region
              # http://cloud-images.ubuntu.com/locator/ec2/
              # version: 14.04 LTS
              # arch: amd64
          Severity: Minor
          Found in lib/cyoi/providers/clients/aws_provider_client.rb - About 1 hr to fix

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

              def execute!
                unless valid_infrastructure?
                  settings["provider"] ||= {}
                  auto_detection unless settings.exists?("provider.name")
                  choose_provider unless settings.exists?("provider.name")
            Severity: Minor
            Found in lib/cyoi/cli/provider.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

            Method auto_detection_choices has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def auto_detection_choices
                fog_choices = {}
                # Prepare menu options:
                # each provider/profile name gets a menu choice option
                fog_config.inject({}) do |iaas_options, fog_profile|
            Severity: Minor
            Found in lib/cyoi/cli/auto_detection/auto_detection_fog.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

              def key_pair_cli
                @key_pair_cli ||= begin
                  provider_name = settings.exists?("provider.name")
                  return nil unless provider_name
                  require "cyoi/cli/provider_key_pair/key_pair_#{settings.provider.name}"
            Severity: Minor
            Found in lib/cyoi/cli/key_pair.rb and 1 other location - About 50 mins to fix
            lib/cyoi/cli/blobstore.rb on lines 38..50

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

            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

              def blobstore_cli
                @blobstore_cli ||= begin
                  provider_name = settings.exists?("provider.name")
                  return nil unless provider_name
                  require "cyoi/cli/provider_blobstore/blobstore_cli_#{settings.provider.name}"
            Severity: Minor
            Found in lib/cyoi/cli/blobstore.rb and 1 other location - About 50 mins to fix
            lib/cyoi/cli/key_pair.rb on lines 39..51

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

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

              def setup_credentials
                puts "\n"
                attributes.set_default("credentials", {})
                credentials = attributes.credentials
                credentials["vsphere_username"] = hl.ask("Username: ").to_s unless credentials.exists?("vsphere_username")
            Severity: Minor
            Found in lib/cyoi/cli/providers/provider_cli_vsphere.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 setup_networking has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def setup_networking
                puts "\n"
                attributes.set_default("network", {})
                network = attributes.network
                network["netmask"] = hl.ask("Netmask: ").to_s unless network.exists?("netmask")
            Severity: Minor
            Found in lib/cyoi/cli/providers/provider_cli_vsphere.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 setup_resources has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def setup_resources
                puts "\n"
                attributes.set_default("resources", {})
                resources = attributes.resources
                resources["persistent_disk"] = hl.ask("Size of Persistent Volume (MB): ", Integer) unless resources.exists?("persistent_disk")
            Severity: Minor
            Found in lib/cyoi/cli/providers/provider_cli_vsphere.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

            Severity
            Category
            Status
            Source
            Language