File relationships.rb
has 569 lines of code (exceeds 250 allowed). Consider refactoring. Open
AbstractRelationship = Class.new(Sequel::Model) do
include ObjectGraph
# Create a relationship instance between two objects with a defined set of properties.
Method transfer
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def self.transfer(target, victims)
target_columns = self.reference_columns_for(target.class)
victims_by_model = victims.reject {|v| (v.class == target.class) && (v.id == target.id)}.group_by(&:class)
- 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 delete_existing_relationships
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def delete_existing_relationships(obj, bump_lock_version_on_referent = false, force = false, predicate = nil)
relationships.each do |relationship_defn|
next if (!relationship_defn.json_property && !force)
- 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 sequel_to_jsonmodel
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def sequel_to_jsonmodel(objs, opts = {})
jsons = super
return jsons if opts[:skip_relationships]
- 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 identify_duplicate_containers
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def self.identify_duplicate_containers(target, relationship, target_col, dups)
find_by_participant(target).each do |target_relationship|
subcontainer = SubContainer[relationship[:sub_container_id]]
target_subcontainer = SubContainer[target_relationship[:sub_container_id]]
# Only proceed if the subcontainer record is empty
- 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 transfer
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.transfer(target, victims)
target_columns = self.reference_columns_for(target.class)
victims_by_model = victims.reject {|v| (v.class == target.class) && (v.id == target.id)}.group_by(&:class)
Method relate
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def self.relate(obj1, obj2, properties)
columns = if obj1.class == obj2.class
# If our two related objects are of the same type, we'll get back multiple
# columns here anyway
raise ReferenceError.new("Can't relate an object to itself") if obj1.id == obj2.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
Method apply_relationships
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def apply_relationships(obj, json, opts, new_record = false)
delete_existing_relationships(obj) if !new_record
@relationships.each do |relationship_name, relationship_defn|
property_name = relationship_defn.json_property
- 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 other_referent_than
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def other_referent_than(obj)
self.class.participating_models.each {|model|
self.class.reference_columns_for(model).each {|column|
if self[column] && (model != obj.class || self[column] != obj.id)
return model.respond_to?(:any_repo) ? model.any_repo[self[column]] : model[self[column]]
- 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 cleanup_container_profile_relationships
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def self.cleanup_container_profile_relationships(victim_container_profiles, target)
target_relationship = nil
find_by_participant(target).each do |target_rlshp|
if !target_rlshp.nil? && target_rlshp.is_a?(Relationships::ContainerProfileTopContainerProfile)
target_relationship = target_rlshp
- 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 transfer_to_repository
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def transfer_to_repository(repository, transfer_group = [])
if transfer_group.empty?
do_id = self.class == DigitalObject ? self[:id] : 0
else
do_id = transfer_group.first.class == DigitalObject ? transfer_group.first[:id] : 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 touch_mtime_of_anyone_related_to
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def touch_mtime_of_anyone_related_to(obj)
now = Time.now
relationships.map do |relationship_defn|
models = relationship_defn.participating_models
Method touch_mtime_of_anyone_related_to
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def touch_mtime_of_anyone_related_to(obj)
now = Time.now
relationships.map do |relationship_defn|
models = relationship_defn.participating_models
- 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 confirm_accepts_target
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.confirm_accepts_target(victim_model, vics)
unless participating_models.include?(victim_model)
found = self.find_by_participant_ids(victim_model, vics.map(&:id))
unless found.empty?
- 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 define_relationship
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def define_relationship(opts)
[:name, :contains_references_to_types].each do |p|
opts[p] or raise "No #{p} given"
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 uri_for_other_referent_than
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def uri_for_other_referent_than(obj)
self.class.participating_models.each {|model|
self.class.reference_columns_for(model).each {|column|
if self[column] && (model != obj.class || self[column] != obj.id)
return model.my_jsonmodel.uri_for(self[column],
- 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
ASModel.all_models.each do |model|
next unless model.associations.include?(:instance)
model
.eager_graph(:instance)
- 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