mattray/spiceweasel

View on GitHub

Showing 64 of 64 total issues

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

          if env =~ /\*/ # wildcard support
            wildenvs = Dir.glob("environments/#{env}")
            # remove anything not ending in .json or .rb
            wildenvs.delete_if { |x| !x.end_with?(".rb", ".json") }
            Spiceweasel::Log.debug("found environments '#{wildenvs}' for wildcard: #{env}")
Severity: Major
Found in lib/spiceweasel/environments.rb and 1 other location - About 1 hr to fix
lib/spiceweasel/roles.rb on lines 55..62

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

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

          if role =~ /\*/ # wildcard support
            wildroles = Dir.glob("roles/#{role}")
            # remove anything not ending in .json or .rb
            wildroles.delete_if { |x| !x.end_with?(".rb", ".json") }
            Spiceweasel::Log.debug("found roles '#{wildroles}' for wildcard: #{role}")
Severity: Major
Found in lib/spiceweasel/roles.rb and 1 other location - About 1 hr to fix
lib/spiceweasel/environments.rb on lines 49..56

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

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 do_flattened_environments has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def do_flattened_environments(cookbooks, environments)
      flatenvs = environments.map(&:keys).flatten
      envfiles = []
      flatenvs.each do |env|
        Spiceweasel::Log.debug("environment: #{env}")
Severity: Minor
Found in lib/spiceweasel/environments.rb - About 1 hr to fix

    Method resolve_cookbooks has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.resolve_cookbooks(berkshelf_cookbooks = {})
          require "solve"
          loader = Chef::CookbookLoader.new(Spiceweasel::Config[:cookbook_dir])
          loader.load_cookbooks
          books = loader.cookbooks_by_name
    Severity: Minor
    Found in lib/spiceweasel/extract_local.rb - About 1 hr to fix

      Method parse_and_validate_options has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def parse_and_validate_options
            ARGV << "-h" if ARGV.empty?
            begin
              parse_options
              # Load knife configuration if using knife config
      Severity: Minor
      Found in lib/spiceweasel/cli.rb - About 1 hr to fix

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

            def cluster_process_nodes(cluster, environment, cookbooks, environments, roles, knifecommands, rootoptions)
              Spiceweasel::Log.debug("cluster::cluster_process_nodes '#{environment}' '#{cluster[environment]}'")
              cluster[environment].each do |node|
                node_name = node.keys.first
                options = node[node_name]["options"] || ""
        Severity: Minor
        Found in lib/spiceweasel/clusters.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 determine_cloud_provider has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def determine_cloud_provider(count, create_command_options, name, options, provider, run_list)
              count.to_i.times do |i|
                if provider.eql?("vsphere")
                  server = node_numerate("knife #{provider}#{Spiceweasel::Config[:knife_options]} vm clone #{options}", i + 1, count)
                elsif provider.eql?("kvm")
        Severity: Minor
        Found in lib/spiceweasel/nodes.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 validate_metadata_or_get_knife_commands_wrapper has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_metadata_or_get_knife_commands_wrapper(name, options, version)
              if File.directory?("cookbooks")
                if @loader.cookbooks_by_name[name]
                  validate_metadata(name, version) unless Spiceweasel::Config[:novalidation]
                else
        Severity: Minor
        Found in lib/spiceweasel/cookbooks.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 parse_and_validate_input has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def parse_and_validate_input(file) # rubocop:disable CyclomaticComplexity
              begin
                Spiceweasel::Log.debug("file: #{file}")
                unless File.file?(file)
                  STDERR.puts "ERROR: #{file} is an invalid manifest file, please check your path."
        Severity: Minor
        Found in lib/spiceweasel/cli.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 process_providers has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def process_providers(names, count, name, options, run_list, create_command_options, knifecommands) # rubocop:disable CyclomaticComplexity
        Severity: Major
        Found in lib/spiceweasel/nodes.rb - About 50 mins to fix

          Method cluster_process_nodes has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def cluster_process_nodes(cluster, environment, cookbooks, environments, roles, knifecommands, rootoptions)
          Severity: Major
          Found in lib/spiceweasel/clusters.rb - About 50 mins to fix

            Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def initialize(nodes, cookbooks, environments, roles, knifecommands, rootoptions) # rubocop:disable CyclomaticComplexity
            Severity: Minor
            Found in lib/spiceweasel/nodes.rb - About 45 mins to fix

              Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def initialize(clusters, cookbooks, environments, roles, knifecommands, rootoptions)
              Severity: Minor
              Found in lib/spiceweasel/clusters.rb - About 45 mins to fix

                Method determine_cloud_provider has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def determine_cloud_provider(count, create_command_options, name, options, provider, run_list)
                Severity: Minor
                Found in lib/spiceweasel/nodes.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          if bundler?
                            parallel += "bundle exec knife #{provider}#{Spiceweasel::Config[:knife_options]} server create #{options}".gsub(/\{\{n\}\}/, "{}")
                          else
                            parallel += "knife #{provider}#{Spiceweasel::Config[:knife_options]} server create #{options}".gsub(/\{\{n\}\}/, "{}")
                          end
                  Severity: Major
                  Found in lib/spiceweasel/nodes.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                            if bundler?
                              parallel += "bundle exec knife #{provider}#{Spiceweasel::Config[:knife_options]} server create #{name} #{options}".gsub(/\{\{n\}\}/, "{}")
                            else
                              parallel += "knife #{provider}#{Spiceweasel::Config[:knife_options]} server create #{name} #{options}".gsub(/\{\{n\}\}/, "{}")
                            end
                    Severity: Major
                    Found in lib/spiceweasel/nodes.rb - About 45 mins to fix

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

                          def self.parse_objects # rubocop:disable CyclomaticComplexity
                            objects = {}
                      
                            # BERKSHELF
                            berksfile = parse_berkshelf(objects)
                      Severity: Minor
                      Found in lib/spiceweasel/extract_local.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 process_parallel has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def process_parallel(count, create_command_options, name, options, provider, run_list)
                      Severity: Minor
                      Found in lib/spiceweasel/nodes.rb - About 45 mins to fix

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

                            def evaluate_configuration(create, delete, manifest)
                              case
                              when Spiceweasel::Config[:extractjson]
                                puts JSON.pretty_generate(manifest)
                              when Spiceweasel::Config[:extractyaml]
                        Severity: Minor
                        Found in lib/spiceweasel/cli.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 do_execute_rebuild has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            def do_execute_rebuild(create, delete)
                              if Spiceweasel::Config[:execute]
                                Execute.new(delete)
                                Execute.new(create)
                              else
                        Severity: Minor
                        Found in lib/spiceweasel/cli.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