af83/chouette-core

View on GitHub

Showing 922 of 922 total issues

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

Navigate.propTypes = {
  journeyPatterns: PropTypes.array.isRequired,
  status: PropTypes.object.isRequired,
  pagination: PropTypes.object.isRequired,
  dispatch: PropTypes.func.isRequired
Severity: Major
Found in app/packs/src/journey_patterns/components/Navigate.js and 4 other locations - About 1 hr to fix
app/packs/src/time_tables/components/PeriodManager.js on lines 77..82
app/packs/src/time_tables/components/PeriodsInDay.js on lines 71..76
app/packs/src/vehicle_journeys/components/ConfirmModal.js on lines 36..41
app/packs/src/vehicle_journeys/components/Navigate.js on lines 51..56

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

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 5 locations. Consider refactoring.
Open

PeriodsInDay.propTypes = {
  value: PropTypes.array.isRequired,
  currentDate: PropTypes.object.isRequired,
  index: PropTypes.number.isRequired,
  onDeletePeriod: PropTypes.func.isRequired
Severity: Major
Found in app/packs/src/time_tables/components/PeriodsInDay.js and 4 other locations - About 1 hr to fix
app/packs/src/journey_patterns/components/Navigate.js on lines 59..64
app/packs/src/time_tables/components/PeriodManager.js on lines 77..82
app/packs/src/vehicle_journeys/components/ConfirmModal.js on lines 36..41
app/packs/src/vehicle_journeys/components/Navigate.js on lines 51..56

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

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

        def flattened_circulation_periods
          periods = time_tables.map(&:periods).flatten
          out = []
          dates = periods.map {|p| [p.period_start, p.period_end + 1.day]}
    
    
    Severity: Minor
    Found in app/models/chouette/vehicle_journey.rb - About 1 hr to fix

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

        def company_params
          return @company_params if @company_params
      
          fields = [
            :objectid,
      Severity: Minor
      Found in app/controllers/companies_controller.rb - About 1 hr to fix

        Method build_instance has 36 lines of code (exceeds 25 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 1 hr to fix

          Function Navigate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          export default function Navigate({ dispatch, vehicleJourneys, pagination, status, filters}) {
            let firstPage = 1
            let lastPage = Math.ceil(pagination.totalCount / pagination.perPage)
            let minVJ = (pagination.page - 1) * pagination.perPage + 1
            if (pagination.totalCount == 0){
          Severity: Minor
          Found in app/packs/src/vehicle_journeys/components/Navigate.js - 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

          Function timetable has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          export default function timetable(state = {}, action) {
            let newState, newPeriods, newDates, newCM
            switch (action.type) {
              case 'RECEIVE_TIME_TABLES':
                let fetchedState = assign({}, state, {
          Severity: Minor
          Found in app/packs/src/time_tables/reducers/timetable.js - 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 extract_zip has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.extract_zip(source_file, target_directory)
                Dir.chdir(target_directory) do
                  Zip::File.open(source_file) do |file|
                    files = 0
                    file.each do |entry|
          Severity: Minor
          Found in app/models/import/shapefile.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 build_object_from_nokogiri_element has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def build_object_from_nokogiri_element(element)
              out = { _node: element }
              element.elements.each do |child|
                key = child.name.underscore.to_sym
          
          
          Severity: Minor
          Found in app/models/import/neptune.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! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def import!
                  netex_source.routing_constraint_zones.each do |zone|
                    decorator = Decorator.new(zone, line_provider: line_provider,
                                                    stop_area_provider: stop_area_provider,
                                                    code_space: code_space,
          Severity: Minor
          Found in app/models/import/netex_generic.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 data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def data(val=nil, &block)
              if val || block_given?
                @options[:data] ||= {}
                if block_given? || val.is_a?(Proc)
                  @options[:data] = block || val
          Severity: Minor
          Found in app/lib/af83/decorator/link.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 checksum_attributes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def checksum_attributes(db_lookup = true)
                [].tap do |attrs|
                  attrs << self.published_journey_name
                  attrs << self.published_journey_identifier
                  loaded_company = association(:company).loaded? ? company : company_light
          Severity: Minor
          Found in app/models/chouette/vehicle_journey.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 update_codes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                  def update_codes(model, resource, event)
                    return unless model.respond_to?(:codes) && resource.respond_to?(:codes_attributes)
          
                    resource.codes_attributes.each do |code_attributes|
                      short_name = code_attributes[:short_name]
          Severity: Minor
          Found in app/lib/chouette/sync/updater.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

          Function componentDidUpdate has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            componentDidUpdate(prevProps, prevState) {
              if(this.props.status.isFetching == false){
                $('.table-2entries').each(function() {
                  var refH = []
                  var refCol = []
          Severity: Minor
          Found in app/packs/src/journey_patterns/components/JourneyPatterns.js - About 1 hr to fix

            Function componentDidUpdate has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              componentDidUpdate(prevProps, prevState) {
                if(this.props.status.isFetching == false){
                  // Don't forget the .modal pre selector to avoid modifying the DOM outside our modal
                  $('.modal .table-2entries').each(function() {
                    var refH = []

              Function initSortables has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                initSortables() {
                  this.container.find(".source-referentials li").draggable({
                    connectToSortable: ".target",
                    placeholder: "placeholder",
                    revert: "invalid",
              Severity: Minor
              Found in app/packs/src/helpers/merge_referentials_selector.js - About 1 hr to fix

                Function constructor has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  constructor(container_selector, formInput){
                    this.formInput = $(formInput);
                    this.container = $(container_selector);
                    this.searchInput = this.container.find('.search');
                    this.loader = this.container.find('.loader');
                Severity: Minor
                Found in app/packs/src/helpers/merge_referentials_selector.js - About 1 hr to fix

                  Method merge! has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def merge!
                      Rails.logger.info "Start Merge##{id} merge for #{referential_ids}"
                  
                      CustomFieldsSupport.within_workgroup(workgroup) do
                        Chouette::Benchmark.measure('merge', merge: id) do
                  Severity: Minor
                  Found in app/models/merge.rb - About 1 hr to fix

                    Method show has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def show
                        @custom_fields = Chouette::JourneyPattern.custom_fields_definitions(referential.workgroup)
                    
                        respond_to do |format|
                          format.json do
                    Severity: Minor
                    Found in app/controllers/journey_patterns_collections_controller.rb - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language