af83/chouette-core

View on GitHub
app/models/import/gtfs.rb

Summary

Maintainability
F
1 wk
Test Coverage

File gtfs.rb has 1154 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Import::Gtfs < Import::Base # rubocop:disable Metrics/ClassLength
  include LocalImportSupport

  after_commit :update_main_resource_status, on:  [:create, :update]

Severity: Major
Found in app/models/import/gtfs.rb - About 2 days to fix

    Method import_stops has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

      def import_stops
        sorted_stops = source.stops.sort_by { |s| s.parent_station.present? ? 1 : 0 }
        @stop_areas_id_by_registration_number = {}
    
        CustomFieldsSupport.within_workgroup(workbench.workgroup) do
    Severity: Minor
    Found in app/models/import/gtfs.rb - About 1 day to fix

    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

    Class Gtfs has 40 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Import::Gtfs < Import::Base # rubocop:disable Metrics/ClassLength
      include LocalImportSupport
    
      after_commit :update_main_resource_status, on:  [:create, :update]
    
    
    Severity: Minor
    Found in app/models/import/gtfs.rb - About 5 hrs to fix

      Method import_routes has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

        def import_routes
          @lines_by_registration_number = {}
      
          CustomFieldsSupport.within_workgroup(workbench.workgroup) do
            create_resource(:routes).each(source.routes, transaction: true) do |route, resource|
      Severity: Minor
      Found in app/models/import/gtfs.rb - About 4 hrs to fix

      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 process_trip has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def process_trip(resource, trip, stop_times)
          begin
            raise InvalidTripSingleStopTime unless stop_times.many?
      
            journey_pattern = find_or_create_journey_pattern(resource, trip, stop_times)
      Severity: Major
      Found in app/models/import/gtfs.rb - About 3 hrs to fix

        Method import_transfers has 79 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def import_transfers
            @trips = {}
            create_resource(:transfers).each(source.transfers, slice: 100, transaction: true) do |transfer, resource|
              next unless transfer.type == '2'
              from_id = @stop_areas_id_by_registration_number[transfer.from_stop_id]
        Severity: Major
        Found in app/models/import/gtfs.rb - About 3 hrs to fix

          Method import_stops has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def import_stops
              sorted_stops = source.stops.sort_by { |s| s.parent_station.present? ? 1 : 0 }
              @stop_areas_id_by_registration_number = {}
          
              CustomFieldsSupport.within_workgroup(workbench.workgroup) do
          Severity: Major
          Found in app/models/import/gtfs.rb - About 3 hrs to fix

            Method find_or_create_journey_pattern has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              def find_or_create_journey_pattern(resource, trip, stop_times)
                journey_pattern_id = journey_pattern_ids[trip_signature(trip, stop_times)]
                return Chouette::JourneyPattern.find(journey_pattern_id) if journey_pattern_id
                stop_points = []
            
            
            Severity: Minor
            Found in app/models/import/gtfs.rb - About 2 hrs to fix

            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_transfers has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              def import_transfers
                @trips = {}
                create_resource(:transfers).each(source.transfers, slice: 100, transaction: true) do |transfer, resource|
                  next unless transfer.type == '2'
                  from_id = @stop_areas_id_by_registration_number[transfer.from_stop_id]
            Severity: Minor
            Found in app/models/import/gtfs.rb - About 2 hrs to fix

            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_routes has 58 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def import_routes
                @lines_by_registration_number = {}
            
                CustomFieldsSupport.within_workgroup(workbench.workgroup) do
                  create_resource(:routes).each(source.routes, transaction: true) do |route, resource|
            Severity: Major
            Found in app/models/import/gtfs.rb - About 2 hrs to fix

              Method find_or_create_journey_pattern has 56 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def find_or_create_journey_pattern(resource, trip, stop_times)
                  journey_pattern_id = journey_pattern_ids[trip_signature(trip, stop_times)]
                  return Chouette::JourneyPattern.find(journey_pattern_id) if journey_pattern_id
                  stop_points = []
              
              
              Severity: Major
              Found in app/models/import/gtfs.rb - About 2 hrs to fix

                Method find_stop_parent_or_create_message has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def find_stop_parent_or_create_message(stop_area_name, parent_station, resource)
                    parent = stop_areas.find_by(registration_number: parent_station)
                
                    unless parent
                      parent = stop_area_referential.stop_areas.find_by(registration_number: parent_station)
                Severity: Minor
                Found in app/models/import/gtfs.rb - About 1 hr to fix

                  Method consistent_stop_times has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def consistent_stop_times(stop_times)
                      times = stop_times.map{|s| [s.arrival_time, s.departure_time]}.flatten.compact
                      times.inject(nil) do |prev, current|
                        current = current.split(':').map &:to_i
                  
                  
                  Severity: Minor
                  Found in app/models/import/gtfs.rb - About 1 hr to fix

                  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_stop_time has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def import_stop_time(stop_time, route, resource, position)
                      unless_parent_model_in_error(Chouette::StopArea, stop_time.stop_id, resource) do
                  
                        if position == 0
                          departure_time = GTFSTime.parse(stop_time.departure_time)
                  Severity: Minor
                  Found in app/models/import/gtfs.rb - About 55 mins to fix

                  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 process_trip has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def process_trip(resource, trip, stop_times)
                      begin
                        raise InvalidTripSingleStopTime unless stop_times.many?
                  
                        journey_pattern = find_or_create_journey_pattern(resource, trip, stop_times)
                  Severity: Minor
                  Found in app/models/import/gtfs.rb - About 45 mins to fix

                  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_stop_point has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def add_stop_point(stop_time, position, starting_day_offset, stop_point, vehicle_journey, worker)
                  Severity: Minor
                  Found in app/models/import/gtfs.rb - About 45 mins to fix

                    Method import! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def import!
                          if specific_default_company
                              self.default_company = specific_default_company
                              self.default_time_zone = ActiveSupport::TimeZone[specific_default_company.time_zone]
                    
                    
                    Severity: Minor
                    Found in app/models/import/gtfs.rb - About 35 mins to fix

                    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! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def import!
                          # Retrieve both calendar and associated calendar_dates into a single GTFS::Service model
                          source.services.each do |service|
                            decorator = Decorator.new(service)
                    
                    
                    Severity: Minor
                    Found in app/models/import/gtfs.rb - About 35 mins to fix

                    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! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def import!
                          source.shapes.each_slice(1000).each do |gtfs_shapes|
                            Shape.transaction do
                              gtfs_shapes.each do |gtfs_shape|
                                decorator = Decorator.new(gtfs_shape, code_space: code_space)
                    Severity: Minor
                    Found in app/models/import/gtfs.rb - About 25 mins to fix

                    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_without_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def import_without_status
                        prepare_referential
                    
                        check_calendar_files_missing_and_create_message || import_resources(:services)
                    
                    
                    Severity: Minor
                    Found in app/models/import/gtfs.rb - About 25 mins to fix

                    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 find_stop_parent_or_create_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def find_stop_parent_or_create_message(stop_area_name, parent_station, resource)
                        parent = stop_areas.find_by(registration_number: parent_station)
                    
                        unless parent
                          parent = stop_area_referential.stop_areas.find_by(registration_number: parent_station)
                    Severity: Minor
                    Found in app/models/import/gtfs.rb - About 25 mins to fix

                    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

                          unless from_id
                            create_message(
                              {
                                criticity: :error,
                                message_key: 'gtfs.transfers.missing_stop_id',
                    Severity: Minor
                    Found in app/models/import/gtfs.rb and 1 other location - About 30 mins to fix
                    app/models/import/gtfs.rb on lines 552..568

                    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 33.

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          unless to_id
                            create_message(
                              {
                                criticity: :error,
                                message_key: 'gtfs.transfers.missing_stop_id',
                    Severity: Minor
                    Found in app/models/import/gtfs.rb and 1 other location - About 30 mins to fix
                    app/models/import/gtfs.rb on lines 534..550

                    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 33.

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                              create_message(
                                {
                                  criticity: :warning,
                                  message_key: 'gtfs.transfers.replacing_duration',
                                  message_attributes: { from_id: transfer.from_stop_id, to_id: transfer.to_stop_id },
                    Severity: Minor
                    Found in app/models/import/gtfs.rb and 1 other location - About 30 mins to fix
                    app/models/import/gtfs.rb on lines 680..695

                    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

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          create_message(
                            {
                              criticity: :error,
                              message_key: 'invalid_stop_time',
                              message_attributes: {
                    Severity: Minor
                    Found in app/models/import/gtfs.rb and 1 other location - About 30 mins to fix
                    app/models/import/gtfs.rb on lines 592..605

                    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

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status