Showing 87 of 87 total issues
Assignment Branch Condition size for acts_as_inheritable is too high. [103/15] Open
def acts_as_inheritable(options)
fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
class_attribute :inheritable_configuration
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [72/10] Open
def acts_as_inheritable(options)
fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
class_attribute :inheritable_configuration
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for verify_parent_name is too high. [37.01/15] Open
def verify_parent_name(new_relation, model_parent)
parent_name = model_parent.class.to_s.downcase
return parent_name if new_relation.respond_to?(parent_name)
many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
many_and_one_associations.each do |association|
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Perceived complexity for acts_as_inheritable is too high. [27/7] Open
def acts_as_inheritable(options)
fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
class_attribute :inheritable_configuration
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for acts_as_inheritable is too high. [25/6] Open
def acts_as_inheritable(options)
fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
class_attribute :inheritable_configuration
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Block has too many lines. [65/25] Open
class_eval do
def has_parent?
parent.present?
end
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Method verify_parent_name
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def verify_parent_name(new_relation, model_parent)
parent_name = model_parent.class.to_s.downcase
return parent_name if new_relation.respond_to?(parent_name)
many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
many_and_one_associations.each do |association|
- 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 acts_as_inheritable
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
def acts_as_inheritable(options)
fail ArgumentError, "Hash expected, got #{options.class.name}" unless options.is_a?(Hash)
fail ArgumentError, 'Empty options' if options[:attributes].blank? && options[:associations].blank?
class_attribute :inheritable_configuration
Method has too many lines. [19/10] Open
def verify_parent_name(new_relation, model_parent)
parent_name = model_parent.class.to_s.downcase
return parent_name if new_relation.respond_to?(parent_name)
many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
many_and_one_associations.each do |association|
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for inherit_attributes is too high. [20.35/15] Open
def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
available_methods = ['update_attributes', 'update_columns']
if has_parent? && self.class.inheritable_configuration[:attributes]
# Attributes
self.class.inheritable_configuration[:attributes].each do |attribute|
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [13/10] Open
def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
available_methods = ['update_attributes', 'update_columns']
if has_parent? && self.class.inheritable_configuration[:attributes]
# Attributes
self.class.inheritable_configuration[:attributes].each do |attribute|
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [13/10] Open
def inherit_instance(current, model_parent, relation, relation_instance)
new_relation = relation_instance.dup
belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
saved =
# Is a `belongs_to` association
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method inherit_attributes
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
available_methods = ['update_attributes', 'update_columns']
if has_parent? && self.class.inheritable_configuration[:attributes]
# Attributes
self.class.inheritable_configuration[:attributes].each do |attribute|
- 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
Perceived complexity for inherit_attributes is too high. [9/7] Open
def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
available_methods = ['update_attributes', 'update_columns']
if has_parent? && self.class.inheritable_configuration[:attributes]
# Attributes
self.class.inheritable_configuration[:attributes].each do |attribute|
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for verify_parent_name is too high. [8/6] Open
def verify_parent_name(new_relation, model_parent)
parent_name = model_parent.class.to_s.downcase
return parent_name if new_relation.respond_to?(parent_name)
many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
many_and_one_associations.each do |association|
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Cyclomatic complexity for inherit_attributes is too high. [8/6] Open
def inherit_attributes(force = false, not_force_for = [], method_to_update = nil)
available_methods = ['update_attributes', 'update_columns']
if has_parent? && self.class.inheritable_configuration[:attributes]
# Attributes
self.class.inheritable_configuration[:attributes].each do |attribute|
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Perceived complexity for verify_parent_name is too high. [8/7] Open
def verify_parent_name(new_relation, model_parent)
parent_name = model_parent.class.to_s.downcase
return parent_name if new_relation.respond_to?(parent_name)
many_and_one_associations = model_parent.class.reflect_on_all_associations.select { |a| a.macro != :belongs_to }
many_and_one_associations.each do |association|
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Assignment Branch Condition size for inherit_instance is too high. [15.17/15] Open
def inherit_instance(current, model_parent, relation, relation_instance)
new_relation = relation_instance.dup
belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
saved =
# Is a `belongs_to` association
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method inherit_instance
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def inherit_instance(current, model_parent, relation, relation_instance)
new_relation = relation_instance.dup
belongs_to_associations_names = model_parent.class.reflect_on_all_associations(:belongs_to).collect(&:name)
saved =
# Is a `belongs_to` association
- 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 inherit_relations
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def inherit_relations(model_parent = send(:parent), current = self)
if model_parent && current.class.method_defined?(:inheritable_configuration) && current.class.inheritable_configuration[:associations]
current.class.inheritable_configuration[:associations].each do |relation|
parent_relation = model_parent.send(relation)
relation_instances = parent_relation.respond_to?(:each) ? parent_relation : [parent_relation].compact
- 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"