Showing 12 of 12 total issues
Method has_closure_tree_root
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
def has_closure_tree_root(assoc_name, options = {})
options[:class_name] ||= assoc_name.to_s.sub(/\Aroot_/, "").classify
options[:foreign_key] ||= self.name.underscore << "_id"
has_one assoc_name, -> { where(parent: nil) }, **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 has_closure_tree_root
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def has_closure_tree_root(assoc_name, options = {})
options[:class_name] ||= assoc_name.to_s.sub(/\Aroot_/, "").classify
options[:foreign_key] ||= self.name.underscore << "_id"
has_one assoc_name, -> { where(parent: nil) }, **options
Method rebuild!
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def rebuild!(called_by_rebuild = false)
_ct.with_advisory_lock do
delete_hierarchy_references unless (defined? @was_new_record) && @was_new_record
hierarchy_class.create!(:ancestor => self, :descendant => self, :generations => 0)
unless root?
- 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 add_sibling
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_sibling(sibling, add_after = true)
fail "can't add self as sibling" if self == sibling
if _ct.dont_order_roots && parent.nil?
raise ClosureTree::RootOrderingDisabledError.new("Root ordering is disabled on this model")
Method add_sibling
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_sibling(sibling, add_after = true)
fail "can't add self as sibling" if self == sibling
if _ct.dont_order_roots && parent.nil?
raise ClosureTree::RootOrderingDisabledError.new("Root ordering is disabled on this model")
- 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 has_closure_tree
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def has_closure_tree(options = {})
options.assert_valid_keys(
:parent_column_name,
:dependent,
:hierarchy_class_name,
Similar blocks of code found in 2 locations. Consider refactoring. Open
def with_descendant(*descendants)
descendant_ids = descendants.map { |ea| ea.is_a?(ActiveRecord::Base) ? ea._ct_id : ea }
scope = descendant_ids.blank? ? all : joins(:descendant_hierarchies).
where("#{_ct.hierarchy_table_name}.descendant_id" => descendant_ids).
where("#{_ct.hierarchy_table_name}.generations > 0").
- 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 41.
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 with_ancestor(*ancestors)
ancestor_ids = ancestors.map { |ea| ea.is_a?(ActiveRecord::Base) ? ea._ct_id : ea }
scope = ancestor_ids.blank? ? all : joins(:ancestor_hierarchies).
where("#{_ct.hierarchy_table_name}.ancestor_id" => ancestor_ids).
where("#{_ct.hierarchy_table_name}.generations > 0").
- 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 41.
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 has_closure_tree
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def has_closure_tree(options = {})
options.assert_valid_keys(
:parent_column_name,
:dependent,
:hierarchy_class_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 build_ancestry_attr_path
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def build_ancestry_attr_path(path, attributes)
path = path.is_a?(Array) ? path.dup : [path]
unless path.first.is_a?(Hash)
if subclass? && has_inheritance_column?
attributes = attributes.with_indifferent_access
- 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 with_descendant
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def with_descendant(*descendants)
descendant_ids = descendants.map { |ea| ea.is_a?(ActiveRecord::Base) ? ea._ct_id : ea }
scope = descendant_ids.blank? ? all : joins(:descendant_hierarchies).
where("#{_ct.hierarchy_table_name}.descendant_id" => descendant_ids).
where("#{_ct.hierarchy_table_name}.generations > 0").
- 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 with_ancestor
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def with_ancestor(*ancestors)
ancestor_ids = ancestors.map { |ea| ea.is_a?(ActiveRecord::Base) ? ea._ct_id : ea }
scope = ancestor_ids.blank? ? all : joins(:ancestor_hierarchies).
where("#{_ct.hierarchy_table_name}.ancestor_id" => ancestor_ids).
where("#{_ct.hierarchy_table_name}.generations > 0").
- 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"