Showing 17 of 17 total issues
Class Network
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
class Network
class << self
def has_reputation_for?(class_name, reputation_name)
reputation_def = get_reputation_def(class_name, reputation_name)
!!reputation_def[:source]
Method update_reputation_value_with_updated_source
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def self.update_reputation_value_with_updated_source(rep, source, oldValue, newSize, weight, process)
weight ||= 1 # weight is 1 by default.
oldSize = rep.received_messages.size
valueBeforeUpdate = oldSize > 0 ? rep.value : nil
newValue = source.value
- 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 get_reputation_def
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def get_reputation_def(class_name, reputation_name)
reputation_def = {}
unless class_name == "ActiveRecord::Base"
reputation_defs = get_reputation_defs(class_name)
reputation_defs[reputation_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 normalized_value
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def normalized_value
if self.active == 1 || self.active == true
max = ReputationSystem::Reputation.max(self.reputation_name, self.target_type)
min = ReputationSystem::Reputation.min(self.reputation_name, self.target_type)
if max && min
- 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 up
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.up
create_table :rs_evaluations do |t|
t.string :reputation_name
t.references :source, :polymorphic => true
t.references :target, :polymorphic => true
Method get_attributes_of
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def get_attributes_of(reputation)
of = reputation[:of]
attrs = (of == :self) ? self : self.instance_eval(of.to_s) if of.is_a?(String) || of.is_a?(Symbol)
attrs = attrs.to_a if attrs.is_a?(ActiveRecord::Associations::CollectionProxy)
attrs = self.instance_exec(self, &of) if of.is_a?(Proc)
- 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 update_reputation_value_with_updated_source
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.update_reputation_value_with_updated_source(rep, source, oldValue, newSize, weight, process)
Method add_reputation_def
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def add_reputation_def(class_name, reputation_name, options)
reputation_defs = get_reputation_defs(class_name)
options[:source] = convert_to_array_if_hash(options[:source])
options[:source_of] ||= []
options[:source_of] = convert_to_array_if_hash(options[:source_of])
- 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 create_scoped_reputation_def
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def create_scoped_reputation_def(class_name, reputation_name, scope, options)
raise ArgumentError, "#{reputation_name} does not have scope." unless has_scopes?(class_name, reputation_name)
scope_options = options.reject { |k, v| ![:source, :aggregated_by].include? k }
reputation_def = get_reputation_def(class_name, reputation_name)
unless is_primary_reputation?(class_name, reputation_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 has_reputation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def has_reputation(reputation_name, options)
has_valid_input = reputation_name && options[:source]
raise ArgumentError, "has_reputation method received invalid arguments." unless has_valid_input
# Overwrites reputation if the same reputation name is declared in the same 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 update_reputation_value_with_new_source
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.update_reputation_value_with_new_source(rep, source, weight, process)
weight ||= 1 # weight is 1 by default.
size = rep.received_messages.size
valueBeforeUpdate = size > 0 ? rep.value : nil
newValue = source.value
- 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 send_reputation_message_to_receiver
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.send_reputation_message_to_receiver(reputation_name, sender, target, scope, oldValue)
Method update_reputation_value
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.update_reputation_value(receiver, sender, weight, process, oldValue)
Method build_select_statement
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def build_select_statement(table_name, reputation_name, select=nil, srn=nil, normalize=false)
Method initialize_reputation_value
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.initialize_reputation_value(receiver, target, process)
name = receiver.reputation_name
unless ReputationSystem::Network.is_primary_reputation?(target.class.name, name)
sender_defs = ReputationSystem::Network.get_reputation_def(target.class.name, name)[:source]
sender_defs.each do |sd|
- 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
def with_reputation_only(*args)
warn "[DEPRECATION] `with_reputation_only` will be deprecated in version 3.0.0. Please use finder methods instead."
reputation_name, srn = parse_arel_query_args(args)
select = build_select_statement_with_reputation_only(table_name, reputation_name)
joins = build_join_statement(table_name, name, srn)
- 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 25.
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_reputation(*args)
warn "[DEPRECATION] `with_reputation` will be deprecated in version 3.0.0. Please use finder methods instead."
reputation_name, srn = parse_arel_query_args(args)
select = build_select_statement(table_name, reputation_name)
joins = build_join_statement(table_name, name, srn)
- 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 25.
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