Showing 829 of 829 total issues
Avoid deeply nested control flow statements. Open
if (obj = (obj.reload rescue nil))
Avoid deeply nested control flow statements. Open
next unless kept
Method do_store
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def do_store(json, key, value, options, schema = {}, store_anyway = false)
Method to_time_span
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def to_time_span(metric = :s)
v = self.abs.to_i
str = ''
h = {
ms: 1000,
- 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 (property_value = json[name])
association = record.send(property_name)
next unless updating || association.blank?
sub_values =
if updating_associations.include?(property_name)
Avoid deeply nested control flow statements. Open
if (association_track = associations[property])
next unless associations[:kept]
sub_values = association_track[:new]
else
associations[property] = {
Avoid deeply nested control flow statements. Open
next if updating && ((property_name == '_id' || primary_fields.include?(name.to_sym)) && !record.send(property_name).nil?)
Avoid deeply nested control flow statements. Open
if (token = message[:token])
TaskToken.where(token: token).delete_all
end
Avoid deeply nested control flow statements. Open
if (sub_record = do_parse_xml(data_type, property_model, sub_element, options, property_schema, nil, nil, property))
record.send("#{property}=", sub_record)
end
Avoid deeply nested control flow statements. Open
members = [members] unless members.is_a?(Array)
Method file_stores
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def file_stores(*args)
if args.length.zero?
options[:file_stores] || [options.key?(:default_file_store) ? default_file_store : Cenit::FileStore::LocalDb]
else
args = args.flatten
- 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 value.save(options)
if new_record || value.instance_variable_get(:@dynamically_created)
value.instance_variable_set(:@dynamically_created, true)
options[:create_collector] << value if options[:create_collector]
else
- 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 39.
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 value.save(options)
if new_record || value.instance_variable_get(:@dynamically_created)
value.instance_variable_set(:@dynamically_created, true)
options[:create_collector] << value if options[:create_collector]
else
- 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 39.
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
Consider simplifying this complex logical expression. Open
if !(value = super).nil? &&
(new_record? || !self.class.build_in_data_type.protecting?(name) ||
(current_user = User.current) &&
(current_user.account_ids.include?(tenant_id) ||
current_user.super_admin?))
Consider simplifying this complex logical expression. Open
if (match = /\Adata_(.+)\Z/.match(symbol.to_s)) &&
COLLECTING_PROPERTIES.include?(relation_name = match[1].to_sym) &&
((args.length.zero? && (options = {})) || args.length == 1 && (options = args[0]).is_a?(Hash))
if (items = send(relation_name)).present?
items
Consider simplifying this complex logical expression. Open
if source_association && source_association.many? &&
(target_association.nil? || !target_association.many?) && # target_association is nil for file mappings
!transformation.bulk_source
sub_map.errors.add(:source, "is a many association and can not be mapped to #{target_data_type.custom_title} | #{schema['title'] || name.to_title} (which is not many) with the non bulk transformation #{transformation.custom_title}")
end
Consider simplifying this complex logical expression. Open
elsif (action == :simple_cross && crossing_models.exclude?(subject.is_a?(Class) ? subject : subject.class)) ||
(subject == ScriptExecution && (user.nil? || !user.super_admin?))
false
else
super || deferred_abilities.any? { |ability| ability.can?(action, subject, *extra_args) }
Consider simplifying this complex logical expression. Open
if property_model && property_value.is_a?(Hash) && property_value['_reference'] && ((property_value[:id].nil? && property_value[:_id].nil?) || options[:skip_refs_binding])
record.send("#{property_name}=", nil)
property_value = Cenit::Utility.deep_remove(property_value, '_reference')
unless (references = record.instance_variable_get(:@_references))
record.instance_variable_set(:@_references, references = {})
Consider simplifying this complex logical expression. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&
Consider simplifying this complex logical expression. Open
if (sub_model = json['_type']) &&
sub_model.is_a?(String) &&
(sub_model = sub_model.start_with?('self[') ? (json.send(:eval, sub_model) rescue nil) : sub_model) &&
(data_type = data_type.find_data_type(sub_model)) &&
(sub_model = data_type.records_model) &&