File osm_pbf_importer_level_db.rb
has 566 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'leveldb-native'
require 'csv'
module ActiveRoad
class OsmPbfImporterLevelDb
Method split_way_with_boundaries
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
def split_way_with_boundaries
Rails.logger.info "Begin to split and affect boundaries to ways in PostgreSql"
start = Time.now
# Update physical roads entirely contains in boundaries
- 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 backup_relations_pgsql
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
def backup_relations_pgsql
Rails.logger.info "Begin to backup relations in PostgreSql"
start = Time.now
relations_parser = ::PbfParser.new(pbf_file)
boundaries_counter = 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 update_nodes_with_way
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def update_nodes_with_way
Rails.logger.info "Update way in nodes in LevelDB"
start = Time.now
ways_parser = ::PbfParser.new(pbf_file)
ways_counter = 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 split_way_with_boundaries
has 106 lines of code (exceeds 25 allowed). Consider refactoring. Open
def split_way_with_boundaries
Rails.logger.info "Begin to split and affect boundaries to ways in PostgreSql"
start = Time.now
# Update physical roads entirely contains in boundaries
Class OsmPbfImporterLevelDb
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
class OsmPbfImporterLevelDb
include OsmPbfImporter
@@csv_batch_size = 100000
cattr_reader :csv_batch_size
Method backup_ways
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def backup_ways
Rails.logger.info "Begin to backup ways in LevelDB"
start = Time.now
ways_parser = ::PbfParser.new(pbf_file)
ways_counter = 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 iterate_ways
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def iterate_ways
Rails.logger.info "Begin to backup ways in PostgreSql"
start = Time.now
ways_counter = 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 backup_logical_roads_pgsql
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def backup_logical_roads_pgsql
Rails.logger.info "Begin to backup logical roads in PostgreSql"
start = Time.now
logical_roads_counter = 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 backup_relations_pgsql
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
def backup_relations_pgsql
Rails.logger.info "Begin to backup relations in PostgreSql"
start = Time.now
relations_parser = ::PbfParser.new(pbf_file)
boundaries_counter = 0
Method iterate_nodes
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def iterate_nodes
Rails.logger.debug "Begin to backup nodes in PostgreSql"
start = Time.now
nodes_counter = street_numbers_counter = 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 iterate_ways
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def iterate_ways
Rails.logger.info "Begin to backup ways in PostgreSql"
start = Time.now
ways_counter = 0
Method save_physical_road_conditionnal_costs_and_junctions
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def save_physical_road_conditionnal_costs_and_junctions
Rails.logger.info "Begin to backup ways in PostgreSql"
start = Time.now
physical_road_conditionnal_costs_counter = junctions_physical_roads_counter = 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 update_nodes_with_way
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_nodes_with_way
Rails.logger.info "Update way in nodes in LevelDB"
start = Time.now
ways_parser = ::PbfParser.new(pbf_file)
ways_counter = 0
Method iterate_nodes
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def iterate_nodes
Rails.logger.debug "Begin to backup nodes in PostgreSql"
start = Time.now
nodes_counter = street_numbers_counter = 0
Method save_physical_road_conditionnal_costs_and_junctions
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save_physical_road_conditionnal_costs_and_junctions
Rails.logger.info "Begin to backup ways in PostgreSql"
start = Time.now
physical_road_conditionnal_costs_counter = junctions_physical_roads_counter = 0
Method initialize
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(boundary_id, old_physical_road_id, old_physical_road_objectid, old_physical_road_tags, old_physical_road_geometry, old_departure_objectid, old_departure_geometry, old_arrival_objectid, old_arrival_geometry, geometry)
Method split_way_with_nodes
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def split_way_with_nodes(way)
nodes_used = []
nodes = []
# Get nodes really used and all nodes (used and for geometry need) for a way
way.nodes.each_with_index do |node_id, index|
- 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 backup_nodes
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def backup_nodes
Rails.logger.info "Begin to backup nodes in LevelDB nodes_database in #{nodes_database_path}"
start = Time.now
nodes_parser = ::PbfParser.new(pbf_file)
nodes_counter = 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if way.arrival == way.old_arrival_geometry
way.arrival_objectid = way.old_arrival_objectid
way.next = nil
else
way.arrival_objectid = way.default_arrival_objectid
- 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 30.
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
if way.departure == way.old_departure_geometry
way.departure_objectid = way.old_departure_objectid
way.previous = nil
else
way.departure_objectid = way.default_departure_objectid
- 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 30.
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