af83/chouette-core

View on GitHub

Showing 922 of 922 total issues

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

      else{
        if (action.isShown){
          newModalProps.vehicleJourney.footnotes.push(action.footnote)
        }else{
          newModalProps.vehicleJourney.footnotes = newModalProps.vehicleJourney.footnotes.filter((f) => {return f.id != action.footnote.id })
Severity: Major
Found in app/packs/src/vehicle_journeys/reducers/modal.js and 1 other location - About 3 hrs to fix
app/packs/src/vehicle_journeys/reducers/modal.js on lines 27..33

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

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

      def build_instance(context, options = {})
        options = { parent: nil, save: false }.update(options)

        parent = options[:parent]
        save = options[:save]
Severity: Minor
Found in app/lib/chouette/factory/model.rb - About 3 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

Function render has 77 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    render() {
        const {
            vjas,
            x,
            y,
Severity: Major
Found in app/packs/src/vehicle_journeys/components/VehicleJourneyAtStop.js - About 3 hrs to fix

    Method candidate_target_attributes has 77 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def candidate_target_attributes # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
              Chouette::ModelAttribute.collection do # rubocop:disable Metrics/BlockLength
                # Chouette::Line
                select Chouette::Line, :name
                select Chouette::Line, :color
    Severity: Major
    Found in app/models/control/format_attribute.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 new_alt_calendar has 77 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def new_alt_calendar(options = {}, &block)
            raise(ArgumentError, "No year given")  unless options.has_key?(:year)
            raise(ArgumentError, "No month given") unless options.has_key?(:month)
        
            block                        ||= Proc.new {|d| nil}
        Severity: Major
        Found in app/helpers/time_tables_helper.rb - About 3 hrs to fix

          Function render has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            render() {
              let id =  _.get(actions.getSelected(this.props.vehicleJourneys), ['0', 'short_id'])
          
              if(this.props.status.isFetching == true) {
                return false

            File table_builder_helper.rb has 293 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require 'table_builder_helper/column'
            require 'table_builder_helper/url'
            
            # table_builder_2
            # A Rails helper that constructs an HTML table from a collection of objects. It
            Severity: Minor
            Found in app/helpers/table_builder_helper.rb - About 3 hrs to fix

              Class Line has 26 methods (exceeds 20 allowed). Consider refactoring.
              Open

                class Line < Chouette::ActiveRecord
                  before_validation :update_unpermitted_blank_values
              
                  has_metadata
                  include LineReferentialSupport
              Severity: Minor
              Found in app/models/chouette/line.rb - About 3 hrs to fix

                Class TimeOfDay has 26 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class TimeOfDay
                  include Comparable
                
                  attr_reader :hour, :minute, :second, :day_offset, :utc_offset, :second_offset
                  alias min minute
                Severity: Minor
                Found in app/lib/time_of_day.rb - About 3 hrs to fix

                  File experimental.rb has 291 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  module Merge::Referential
                  
                    module Sanitizer
                      def sanitize_joins(query)
                        # in fact, new.slug is already sanitized but .. it is better to be safe than sorry.
                  Severity: Minor
                  Found in app/models/merge/referential/experimental.rb - About 3 hrs to fix

                    Method thead has 73 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def thead(collection, columns, sortable, selectable, has_links, overhead, model, action)
                        content_tag :thead do
                          # Inserts overhead content if any specified
                          over_head = ''
                    
                    
                    Severity: Major
                    Found in app/helpers/table_builder_helper.rb - About 2 hrs to fix

                      Function vehicleJourney has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const vehicleJourney= (state = {}, action, keep) => {
                        switch (action.type) {
                          case 'SELECT_VEHICLEJOURNEY':
                            return _.assign({}, state, {selected: !state.selected})
                          case 'CANCEL_SELECTION':
                      Severity: Minor
                      Found in app/packs/src/vehicle_journeys/reducers/vehicleJourneys.js - 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 handle_serialize_option has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                            def handle_serialize_option attribute_name, opts
                              serializer = opts[:serialize]
                          
                              define_method attribute_name do
                                return nil unless respond_to?(:options)
                      Severity: Minor
                      Found in app/models/concerns/options_support.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 valid_days has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def self.valid_days(int_day_types)
                            # Build an array with day of calendar week (1-7, Monday is 1).
                            [].tap do |valid_days|
                              valid_days << 1  if day_by_mask(int_day_types,MONDAY)
                              valid_days << 2  if day_by_mask(int_day_types,TUESDAY)
                      Severity: Minor
                      Found in app/models/concerns/application_days_support.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 remove_periods! has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def remove_periods!(removed_periods)
                            deleted_dates = []
                            dates.each do |date|
                              if removed_periods.any? { |p| p.include? date.date }
                                 deleted_dates << date
                      Severity: Minor
                      Found in app/models/chouette/time_table.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 fetch has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.fetch key, opts={}
                          key = key.to_s
                          unless keys.include?(key)
                            logger.warn("Fetching unexpected ENV key `#{key}`")
                            keys << key
                      Severity: Minor
                      Found in app/lib/smart_env.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

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

                        class Batch
                          def address(position, key: nil)
                            item = Item.new(position)
                      
                            # Reuse an already defined Item
                      Severity: Major
                      Found in app/lib/reverse_geocode.rb and 1 other location - About 2 hrs to fix
                      app/lib/route_planner.rb on lines 23..72

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

                      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

                        class Batch
                          def shape(points, key: nil)
                            item = Item.new(points)
                      
                            # Reuse an already defined Item
                      Severity: Major
                      Found in app/lib/route_planner.rb and 1 other location - About 2 hrs to fix
                      app/lib/reverse_geocode.rb on lines 23..72

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

                      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

                      Severity
                      Category
                      Status
                      Source
                      Language