Showing 27 of 27 total issues
File base.rb
has 295 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'itamae'
require 'shellwords'
require 'hashie'
module Itamae
Class Base
has 26 methods (exceeds 20 allowed). Consider refactoring. Open
class Base
class EvalContext
attr_reader :attributes
attr_reader :notifications
attr_reader :subscriptions
Method run_action
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def run_action(action)
runner.handler.event(:action, action: action) do
original_attributes = @attributes # preserve and restore later
@current_action = action
- 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 run
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def run(specific_action = nil)
runner.handler.event(:resource, resource_type: resource_type, resource_name: resource_name) do
Itamae.logger.debug "#{resource_type}[#{resource_name}]"
Itamae.logger.with_indent_if(Itamae.logger.debug?) do
- 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 action_create
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def action_create(options)
if run_specinfra(:check_user_exists, attributes.username)
if attributes.uid && attributes.uid != current.uid
run_specinfra(:update_user_uid, attributes.username, attributes.uid)
updated!
- 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_attributes
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def process_attributes
self.class.defined_attributes.each_pair do |key, details|
@attributes[key] ||= @resource_name if details[:default_name]
@attributes[key] = details[:default] if details.has_key?(:default) && !@attributes.has_key?(key)
- 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 action_create
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def action_create(options)
if !current.exist && !@temppath
run_command(["touch", attributes.path])
end
- 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 action_create
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_create(options)
if run_specinfra(:check_user_exists, attributes.username)
if attributes.uid && attributes.uid != current.uid
run_specinfra(:update_user_uid, attributes.username, attributes.uid)
updated!
Method run_action
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_action(action)
runner.handler.event(:action, action: action) do
original_attributes = @attributes # preserve and restore later
@current_action = action
Method action_sync
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def action_sync(options)
ensure_git_available
new_repository = false
- 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 run_command
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_command(commands, options = {})
options = {error: true}.merge(options)
command = build_command(commands, options)
Itamae.logger.debug "Executing `#{command}`..."
Method action_sync
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def action_sync(options)
ensure_git_available
new_repository = false
Method run_command
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def run_command(commands, options = {})
options = {error: true}.merge(options)
command = build_command(commands, options)
Itamae.logger.debug "Executing `#{command}`..."
- 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
def set_current_attributes
current.exist = run_specinfra(:check_file_is_directory, attributes.path)
if current.exist
current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
- 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 46.
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
def set_current_attributes
current.exist = run_specinfra(:check_file_is_file, attributes.path)
if current.exist
current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
- 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 46.
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 find_source_file
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def find_source_file
if attributes.source == :auto
dirs = attributes.path.split(::File::SEPARATOR)
dirs.shift if dirs.first == ""
- 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 find_recipe_in_gem
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def find_recipe_in_gem(recipe)
plugin_name, recipe_file = recipe.split('::', 2)
recipe_file = recipe_file.gsub("::", "/") if recipe_file
gem_name = "itamae-plugin-recipe-#{plugin_name}"
- 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 compare_file
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def compare_file
compare_to = if current.exist
attributes.path
else
'/dev/null'
- 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 action_create
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def action_create(options)
if attributes.mode
run_specinfra(:change_file_mode, @temppath, attributes.mode)
end
if attributes.owner || attributes.group
- 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 notify
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def notify
(notifications + recipe.children.subscribing(self)).each do |notification|
message = "Notifying #{notification.action} to #{notification.action_resource.resource_type} resource '#{notification.action_resource.resource_name}'"
if notification.delayed?
- 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"