File configure_proxy.rb
has 310 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Fluent
module Config
class ConfigureProxy
attr_accessor :name, :final, :param_name, :init, :required, :multi, :alias, :configured_in_section
attr_accessor :argument, :params, :defaults, :descriptions, :sections
Method merge
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def merge(other) # self is base class, other is subclass
return merge_for_finalized(other) if self.final?
[:param_name, :required, :multi, :alias, :configured_in_section].each do |prohibited_name|
if overwrite?(other, prohibited_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 merge_for_finalized
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def merge_for_finalized(other)
# list what subclass can do for finalized section
# * append params/defaults/sections which are missing in superclass
# * change default values of superclass
# * overwrite init to make it enable to instantiate section objects with added default values
- 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 ConfigureProxy
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class ConfigureProxy
attr_accessor :name, :final, :param_name, :init, :required, :multi, :alias, :configured_in_section
attr_accessor :argument, :params, :defaults, :descriptions, :sections
# config_param :desc, :string, default: '....'
# config_set_default :buffer_type, :memory
Method dump_config_definition
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def dump_config_definition
dumped_config = {}
if @argument
argument_name, _block, options = @argument
options[:required] = !@defaults.key?(argument_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 merge_for_finalized
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def merge_for_finalized(other)
# list what subclass can do for finalized section
# * append params/defaults/sections which are missing in superclass
# * change default values of superclass
# * overwrite init to make it enable to instantiate section objects with added default values
Method config_parameter_option_validate!
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def config_parameter_option_validate!(name, type, **kwargs, &block)
if type.nil? && !block
type = :string
end
kwargs.each_key do |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 parameter_configuration
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def parameter_configuration(name, type = nil, **kwargs, &block)
config_parameter_option_validate!(name, type, **kwargs, &block)
name = name.to_sym
- 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 dump_config_definition
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def dump_config_definition
dumped_config = {}
if @argument
argument_name, _block, options = @argument
options[:required] = !@defaults.key?(argument_name)
Method parameter_configuration
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def parameter_configuration(name, type = nil, **kwargs, &block)
config_parameter_option_validate!(name, type, **kwargs, &block)
name = name.to_sym
Method merge
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def merge(other) # self is base class, other is subclass
return merge_for_finalized(other) if self.final?
[:param_name, :required, :multi, :alias, :configured_in_section].each do |prohibited_name|
if overwrite?(other, prohibited_name)
Method option_value_type!
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def option_value_type!(name, opts, key, klass=nil, type: nil)
if opts.has_key?(key)
if klass && !opts[key].is_a?(klass)
raise ArgumentError, "#{name}: #{key} must be a #{klass}, but #{opts[key].class}"
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
(self.sections.keys + other.sections.keys).uniq.each do |section_key|
self_section = self.sections[section_key]
other_section = other.sections[section_key]
merged_section = if self_section && other_section
self_section.merge(other_section)
- 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 44.
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
(self.sections.keys + other.sections.keys).uniq.each do |section_key|
self_section = self.sections[section_key]
other_section = other.sections[section_key]
merged_section = if self_section && other_section
other_section.merge(self_section)
- 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 44.
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