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}")
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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}")
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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}")
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
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
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"] || ""
- Read upRead up
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")
- Read upRead up
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
- Read upRead up
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."
- Read upRead up
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
Method cluster_process_nodes
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def cluster_process_nodes(cluster, environment, cookbooks, environments, roles, knifecommands, rootoptions)
Method initialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(nodes, cookbooks, environments, roles, knifecommands, rootoptions) # rubocop:disable CyclomaticComplexity
Method initialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(clusters, cookbooks, environments, roles, knifecommands, rootoptions)
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)
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
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
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)
- Read upRead up
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)
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]
- Read upRead up
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
- Read upRead up
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"