af83/chouette-core

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

Summary

Maintainability
F
1 wk
Test Coverage

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

class Import::Gtfs < Import::Base
  include LocalImportSupport

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

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

    Method import_stops has a Cognitive Complexity of 58 (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 42 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class Import::Gtfs < Import::Base
      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 83 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def process_trip(resource, trip, stop_times)
          begin
            raise InvalidTripSingleStopTime unless stop_times.many?
            raise InvalidTripTimesError unless consistent_stop_times(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 77 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 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_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 process_trip has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  def process_trip(resource, trip, stop_times)
                    begin
                      raise InvalidTripSingleStopTime unless stop_times.many?
                      raise InvalidTripTimesError unless consistent_stop_times(stop_times)
                
                
                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 improve_shape has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def improve_shape(journey_pattern)
                      return unless journey_pattern.shape_id
                      return unless improved_shape_ids.add?(journey_pattern.shape_id)
                
                      shape = journey_pattern.shape
                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 import! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    def import!
                      if specific_default_company
                          self.default_company = specific_default_company
                
                          if specific_default_company&.time_zone
                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 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!
                        # 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 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

                  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

                  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 543..559

                  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 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 561..577

                  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: :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 601..614

                  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: :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 729..744

                  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