File cli.rb
has 540 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'thor'
require 'json'
require 'yaml'
require 'highline/import'
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'
- 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_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+$/)
- 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 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?('/')
- 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 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']
- 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_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
- 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 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}' ..."
- 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 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)
- 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
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
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|
- 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 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)
Method output
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def output(data = {}, indent = 0)
case @options['format']
when 'json'
puts JSON.pretty_generate(data)
when 'yaml'
Method rest
has 28 lines of code (exceeds 25 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?('/')
Method delete_from_file
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def delete_from_file(file_path)
client_setup
resource = OneviewSDK::Resource.from_file(@client, file_path)
fail_nice("#{resource.class.name.split('::').last} '#{resource[:name] || resource[:uri]}' Not Found", 2) unless resource.retrieve!
return unless options['force'] || agree("Delete '#{resource[:name]}'? [Y/N] ")
- 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 update
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def update(type, name)
resource_class = parse_type(type)
client_setup
fail_nice 'Must set the hash or json option' unless @options['hash'] || @options['json']
fail_nice 'Must set the hash OR json option. Not both' if @options['hash'] && @options['json']
- 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
Avoid deeply nested control flow statements. Open
puts "#{' ' * indent}#{d.nil? ? 'nil' : d}"
Method initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
Method env
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def env
data = {}
OneviewSDK::ENV_VARS.each { |k| data[k] = ENV[k] }
if @options['format'] == 'human'
data.each do |key, value|
- 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 search
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def search(type)
resource_class = parse_type(type)
client_setup
filter = parse_hash(options['filter'])
matches = resource_class.find_by(@client, filter)
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if options['attribute']
data = select_attributes_from_multiple(options['attribute'], all)
output data, -2 # Shift left by 2 so things look right
else # List names only by default
names = []
- 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 28.
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 options['attribute']
data = select_attributes_from_multiple(options['attribute'], matches)
output data, -2 # Shift left by 2 so things look right
else # List names only by default
names = []
- 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 28.
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