File table.rb
has 1189 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'forwardable'
require_relative './table/column_typecaster'
require_relative './table/privacy_manager'
require_relative './table/relator'
Class Table
has 120 methods (exceeds 20 allowed). Consider refactoring. Open
class Table
extend Forwardable
include Carto::TableUtils
include ::LoggerHelper
Method update_row!
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def update_row!(row_id, raw_attributes)
retries = 0
rows_updated = 0
owner.in_database do |user_database|
- 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 insert_row!
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def insert_row!(raw_attributes)
primary_key = nil
owner.in_database do |user_database|
schema = user_database.schema(name, schema: owner.database_schema, reload: true).map{|c| c.first}
raw_attributes.delete(:id) unless schema.include?(: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 records
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def records(options = {})
rows = []
records_count = 0
page, per_page = CartoDB::Pagination.get_page_and_per_page(options)
order_by_column = options[:order_by] || 'cartodb_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 schema
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def schema(options = {})
first_columns = []
middle_columns = []
last_columns = []
owner.in_database.schema(name, schema: owner.database_schema, reload: options.fetch(:reload, true)).each do |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 set_the_geom_column!
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def set_the_geom_column!(type = nil)
if type.nil?
if self.schema(reload: true).flatten.include?(THE_GEOM)
if self.schema.select{ |k| k[0] == THE_GEOM }.first[1] == 'geometry'
row = owner.in_database["select GeometryType(#{THE_GEOM}) FROM #{qualified_table_name} where #{THE_GEOM} is not null limit 1"].first
- 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 after_create
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def after_create
grant_select_to_tiler_user
@force_schema = nil
self.new_table = true
- 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 import_cleanup
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def import_cleanup
# When tables are created using ogr2ogr they are added a ogc_fid or gid primary key
# In that case:
# - If cartodb_id already exists, remove ogc_fid
# - If cartodb_id does not exist, treat this field as the auxiliary 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 records
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
def records(options = {})
rows = []
records_count = 0
page, per_page = CartoDB::Pagination.get_page_and_per_page(options)
order_by_column = options[:order_by] || 'cartodb_id'
Method update_name_changes
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def update_name_changes
if @name_changed_from.present? && @name_changed_from != name
reload
unless register_table_only
- 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 import_cleanup
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def import_cleanup
# When tables are created using ogr2ogr they are added a ogc_fid or gid primary key
# In that case:
# - If cartodb_id already exists, remove ogc_fid
# - If cartodb_id does not exist, treat this field as the auxiliary column
Method update_row!
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_row!(row_id, raw_attributes)
retries = 0
rows_updated = 0
owner.in_database do |user_database|
Method update_name_changes
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_name_changes
if @name_changed_from.present? && @name_changed_from != name
reload
unless register_table_only
Method insert_row!
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def insert_row!(raw_attributes)
primary_key = nil
owner.in_database do |user_database|
schema = user_database.schema(name, schema: owner.database_schema, reload: true).map{|c| c.first}
raw_attributes.delete(:id) unless schema.include?(:id)
Method import_to_cartodb
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def import_to_cartodb(uniname = nil)
if migrate_existing_table.present? || uniname
data_import.data_type = DataImport::TYPE_EXTERNAL_TABLE if data_import.data_type.nil?
data_import.data_source = migrate_existing_table || uniname
data_import.save
- 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 set_the_geom_column!
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_the_geom_column!(type = nil)
if type.nil?
if self.schema(reload: true).flatten.include?(THE_GEOM)
if self.schema.select{ |k| k[0] == THE_GEOM }.first[1] == 'geometry'
row = owner.in_database["select GeometryType(#{THE_GEOM}) FROM #{qualified_table_name} where #{THE_GEOM} is not null limit 1"].first
Method before_create
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def before_create
raise CartoDB::QuotaExceeded if owner.over_table_quota?
# The Table model only migrates now, never imports
if migrate_existing_table.present?
Method record
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def record(identifier)
row = nil
owner.in_database do |user_database|
select_sql = schema.map { |column|
name, type = 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 before_create
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def before_create
raise CartoDB::QuotaExceeded if owner.over_table_quota?
# The Table model only migrates now, never imports
if migrate_existing_table.present?
- 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 manage_tags
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def manage_tags
if @user_table[:tags].blank?
Carto::Tag.where(user_id: user_id, table_id: id).each(&:destroy)
else
tag_names = @user_table.tags.split(',')
- 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 after_create
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def after_create
grant_select_to_tiler_user
@force_schema = nil
self.new_table = true
Method schema
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def schema(options = {})
first_columns = []
middle_columns = []
last_columns = []
owner.in_database.schema(name, schema: owner.database_schema, reload: options.fetch(:reload, true)).each do |column|
Method import_to_cartodb
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def import_to_cartodb(uniname = nil)
if migrate_existing_table.present? || uniname
data_import.data_type = DataImport::TYPE_EXTERNAL_TABLE if data_import.data_type.nil?
data_import.data_source = migrate_existing_table || uniname
data_import.save
Method name=
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def name=(value)
value = value.downcase if value
return if value == @user_table.name || value.blank?
new_name = register_table_only ? value : get_valid_name(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 create_table_in_database!
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def create_table_in_database!
self.name ||= get_valid_name(self.name)
owner.in_database do |user_database|
if force_schema.blank?
- 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 handle_creation_error
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def handle_creation_error(e)
log_info(message: 'table#create error', exception: e)
# Remove the table, except if it already exists
unless self.name.blank? || e.message =~ /relation .* already exists/
@data_import.log.append ("Import ERROR: Dropping table #{qualified_table_name}") if @data_import
- 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 (retries += 1) > MAX_UPDATE_ROW_RETRIES
log_error(message: 'Max update_row! retries reached',
user_id: user_id,
qualified_table_name: qualified_table_name,
row_id: row_id,
Method get_by_id
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_by_id(table_id, viewer_user)
table = nil
return table unless viewer_user
table_temp = Carto::UserTable.where(id: table_id).first.service
- 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_all_by_names
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_all_by_names(names, viewer_user)
names.map { |t|
user_id = viewer_user.id
table_name, table_schema = Table.table_and_schema(t)
unless table_schema.nil?
- 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_all_user_tables_by_names
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def self.get_all_user_tables_by_names(names, viewer_user)
names.map { |t|
user_id = viewer_user.id
table_name, table_schema = Table.table_and_schema(t)
unless table_schema.nil?
- 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_column!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_column!(options)
raise CartoDB::InvalidColumnName if CartoDB::Importer2::Column.rejected?(options[:name])
type = options[:type].convert_to_db_type
cartodb_type = options[:type].convert_to_cartodb_type
# FIXME: consider CartoDB::Importer2::Column.get_valid_column_name with CURRENT_COLUMN_SANITIZATION_VERSION
- 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 cartodbfy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def cartodbfy
start = Time.now
schema_name = owner.database_schema
table_name = "#{owner.database_schema}.#{self.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 rename_column
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def rename_column(old_name, new_name='')
raise 'Please provide a column name' if new_name.empty?
raise 'This column cannot be renamed' if CARTODB_COLUMNS.include?(old_name.to_s)
if CartoDB::Importer2::Column.reserved_or_unsupported?(new_name) || CARTODB_COLUMNS.include?(new_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 update_the_geom!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update_the_geom!(attributes, primary_key)
return unless attributes[THE_GEOM].present? && attributes[THE_GEOM] != 'GeoJSON'
geojson = attributes[THE_GEOM]
begin
- 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 the_geom_type=
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def the_geom_type=(value)
self.the_geom_type_value = case value.downcase
when 'geometry'
'geometry'
when 'point'
- 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 add_table_to_stats
CartoDB::Stats::UserTables.instance.update_tables_counter(1)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_user(1, self.owner.username)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_host(1)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_plan(1, self.owner.account_type)
- 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 32.
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 remove_table_from_stats
CartoDB::Stats::UserTables.instance.update_tables_counter(-1)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_user(-1, self.owner.username)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_host(-1)
CartoDB::Stats::UserTables.instance.update_tables_counter_per_plan(-1, self.owner.account_type)
- 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 32.
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