Method modify_conditions
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
def modify_conditions(node)
if node.kind_of? Arel::TreeManager
# We have another sub-tree, investigate its core, which is a SelectCore
node.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
modify_conditions(core)
- 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
File historic_active_record_relation.rb
has 332 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
attr_accessor :timestamp
include ActiveRecord::Delegation::ClassSpecificRelation
Class HistoricActiveRecordRelation
has 25 methods (exceeds 20 allowed). Consider refactoring. Open
class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
attr_accessor :timestamp
include ActiveRecord::Delegation::ClassSpecificRelation
Method modify_conditions
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
def modify_conditions(node)
if node.kind_of? Arel::TreeManager
# We have another sub-tree, investigate its core, which is a SelectCore
node.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
modify_conditions(core)
Method substitute_database_table_in_predicate
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def substitute_database_table_in_predicate(predicate)
case predicate
when String
gsub_table_names_in_sql_string!(predicate)
when Arel::Nodes::HomogeneousIn,
Method modify_joins
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def modify_joins(arel)
arel.instance_variable_get(:@ast).instance_variable_get(:@cores).each do |core|
core.instance_variable_get(:@source).right.each do |node|
if node.kind_of? Arel::Nodes::StringJoin
gsub_table_names_in_sql_string!(node.left)
- 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 substitute_database_table_in_predicate
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def substitute_database_table_in_predicate(predicate)
case predicate
when String
gsub_table_names_in_sql_string!(predicate)
when Arel::Nodes::HomogeneousIn,
- 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
if node.name == "id"
# ID needs to be pulled from the Journal table
node.relation = Journal.arel_table
node.name = "journable_id"
else
Avoid deeply nested control flow statements. Open
elsif node.kind_of? Arel::Nodes::NodeExpression
# Generic case, go through left and right
modify_conditions(node.left) if node.respond_to?(:left) && node.left
modify_conditions(node.right) if node.respond_to?(:right) && node.right
Avoid deeply nested control flow statements. Open
if node.left == model.arel_table
node.left = model.journal_class.arel_table
end
Method modify_order_clauses
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def modify_order_clauses(arel)
arel.instance_variable_get(:@ast).instance_variable_get(:@orders).each do |order_clause|
if order_clause.kind_of? Arel::Nodes::SqlLiteral
gsub_table_names_in_sql_string!(order_clause)
elsif order_clause.expr.relation == model.arel_table
- 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 pluck
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def pluck(*column_names)
column_names.map! do |column_name|
case column_name
when :id, "id"
"journals.journable_id"
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if order_clause.kind_of? Arel::Nodes::SqlLiteral
gsub_table_names_in_sql_string!(order_clause)
elsif order_clause.expr.relation == model.arel_table
if order_clause.expr.name == "id"
order_clause.expr.name = "journable_id"
- 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 37.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if order_clause.kind_of? Arel::Nodes::SqlLiteral
gsub_table_names_in_sql_string!(order_clause)
elsif order_clause.expr.relation == model.arel_table
if order_clause.expr.name == "id"
order_clause.expr.name = "journable_id"
- 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 37.
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