robertgauld/rail_feeds

View on GitHub

Showing 10 of 10 total issues

File train_schedule.rb has 252 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module RailFeeds
  module NetworkRail
    module Schedule
      # rubocop:disable Metrics/ClassLength
      # A class for holding information about a particular train
Severity: Minor
Found in lib/rail_feeds/network_rail/schedule/train_schedule.rb - About 2 hrs to fix

    Method path_for has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

            def path_for(toc, day, format)
              toc = "#{toc}_TOC" unless %w[ALL FREIGHT].include?(toc)
    
              if format.eql?(:cif)
                unless toc.eql?('ALL')
    Severity: Minor
    Found in lib/rail_feeds/network_rail/schedule/fetcher.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 to_json has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def to_json(**opts)
              {
                'JsonScheduleV1' => {
                  'CIF_bank_holiday_running' => bank_holiday_running,
                  'CIF_stp_indicator' => stp_indicator_to_cif,
    Severity: Minor
    Found in lib/rail_feeds/network_rail/schedule/train_schedule.rb - About 1 hr to fix

      Method from_json has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def self.from_json(json)
                data = ::JSON.parse(json)['JsonScheduleV1']
      
                locations = data.dig('schedule_segment', 'schedule_location')&.map do |location|
                  location_from_json location
      Severity: Minor
      Found in lib/rail_feeds/network_rail/schedule/train_schedule.rb - About 1 hr to fix

        Method ensure_correct_update_order has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                def ensure_correct_update_order(header)
                  if last_header.nil?
                    # No data whatsoever - this must be a full extract
                    unless header.full?
                      fail ArgumentError,
        Severity: Minor
        Found in lib/rail_feeds/network_rail/schedule/data.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 basic_to_cif has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def basic_to_cif
                  format('%-80.80s', [
                    'BSN',
                    format('%-6.6s', uid),
                    format('%-6.6s', start_date&.strftime('%y%m%d')),
        Severity: Minor
        Found in lib/rail_feeds/network_rail/schedule/train_schedule.rb - About 1 hr to fix

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

                    def parse_association_line(line)
                      hash = ::JSON.parse(line)['JsonAssociationV1']
          
                      case hash['transaction_type'].downcase
                      when 'create'
          Severity: Minor
          Found in lib/rail_feeds/network_rail/schedule/parser/json.rb and 1 other location - About 50 mins to fix
          lib/rail_feeds/network_rail/schedule/parser/json.rb on lines 67..78

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

          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

                    def parse_schedule_line(line)
                      hash = ::JSON.parse(line)['JsonScheduleV1']
          
                      case hash['transaction_type'].downcase
                      when 'create'
          Severity: Minor
          Found in lib/rail_feeds/network_rail/schedule/parser/json.rb and 1 other location - About 50 mins to fix
          lib/rail_feeds/network_rail/schedule/parser/json.rb on lines 52..63

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

          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

          Method parse_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                  def parse_file(file)
                    @file_ended = false
                    @stop_parsing = false
          
                    file.each_line do |line|
          Severity: Minor
          Found in lib/rail_feeds/network_rail/schedule/parser.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 parse_line has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

                    def parse_line(line)
                      if line.start_with? '{"TiplocV1":'
                        parse_tiploc_line line
                      elsif line.start_with? '{"JsonAssociationV1":'
                        parse_association_line line
          Severity: Minor
          Found in lib/rail_feeds/network_rail/schedule/parser/json.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

          Severity
          Category
          Status
          Source
          Language