BathHacked/energy-sparks

View on GitHub

Showing 151 of 266 total issues

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

    def perform
      return unless @meter.data_source.nil? || @meter.data_source.load_tariffs

      todays_tariff = N3rgyTariffDownloader.new(meter: @meter).current_tariff

Severity: Minor
Found in app/services/amr/n3rgy_energy_tariff_loader.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 include_fuel_type_in_suggestions? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def include_fuel_type_in_suggestions?(fuel_type)
      return false unless school_target
      return false unless @school.configuration.suggest_annual_estimate_for_fuel_type?(fuel_type)
      target_start_date = school_target.start_date
      fuel_type_start = @school.configuration.meter_start_date(fuel_type)
Severity: Minor
Found in app/services/targets/suggest_estimates_service.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 build_breadcrumbs has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def build_breadcrumbs
    @breadcrumbs = []

    if @tariff_holder.school_group?
      @breadcrumbs += [
Severity: Minor
Found in app/controllers/concerns/energy_tariffable.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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    raise ArgumentError unless CalendarEventType.where(holiday: true).any?

    holiday_type = CalendarEventType.holiday.first
    events = @calendar.calendar_events
Severity: Minor
Found in app/services/holiday_factory.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 handle_header has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_header(array_of_rows)
      if array_of_rows.empty?
        array_of_rows
      elsif array_of_rows.first.join(',') == @config.header_example
        array_of_rows[1, array_of_rows.length]
Severity: Minor
Found in app/services/amr/data_feed_validator.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 convert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def convert(val)
        return val if val.nil? || !needs_conversion?(val)

        if [true, false].include? val
          val.to_s
Severity: Minor
Found in app/services/alerts/adapters/analytics_adapter.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 perform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def perform
      updated_meters = []
      @meters.each do |meter|
        meter.update!(dcc_checked_at: DateTime.now, dcc_meter: Meters::N3rgyMeteringService.new(meter).type)
        updated_meters << meter if meter.saved_change_to_dcc_meter?
Severity: Minor
Found in app/services/meters/dcc_checker.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 check_meters! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def check_meters!(meters)
    raise MeterReviewError.new('You must select at least one meter') if meters.empty?
    meters.each do |meter|
      raise MeterReviewError.new("#{meter.mpan_mprn} is not a DCC meter") unless meter.dcc_meter?
      raise MeterReviewError.new("#{meter.mpan_mprn} not found in DCC api") unless is_meter_known_to_n3rgy?(meter)
Severity: Minor
Found in app/services/meter_review_service.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_and_mirror_entry_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def find_and_mirror_entry_for(key, options)
        entry = lookup('en', key, options[:scope], options)
        entry = entry.dup if entry.is_a?(String)

        entry = pluralize('en', entry, options[:count]) if options[:count]
Severity: Minor
Found in app/services/i18n/backend/mirror.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 update_previous_events has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update_previous_events(calendar_event, pre_save, post_save)
    previous_event = @calendar.terms_and_holidays.find_by(end_date: calendar_event.start_date_was - 1.day)
    if previous_event
      callback = calendar_event.start_date > calendar_event.start_date_was ? post_save : pre_save
      new_event_end = calendar_event.start_date - 1.day
Severity: Minor
Found in app/services/holiday_factory.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 update_following_events has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def update_following_events(calendar_event, pre_save, post_save)
    following_event = @calendar.terms_and_holidays.find_by(start_date: calendar_event.end_date_was + 1.day)
    if following_event
      callback = calendar_event.end_date > calendar_event.end_date_was ? pre_save : post_save
      new_event_start = calendar_event.end_date + 1.day
Severity: Minor
Found in app/services/holiday_factory.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 get_missing_array has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def get_missing_array(first_reading, reading_summary)
      return [] if first_reading.nil?
      missing_array = (first_reading.reading_date.to_date..Time.zone.today).collect do |day|
        if ! reading_summary.key?(day)
          [day, 'No readings']
Severity: Minor
Found in app/controllers/data_feeds/generic_controller.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 substitute_missing_days has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def substitute_missing_days(missing_days, data, start_date, end_date)
      substitute_days = {}
      missing_days.each do |missing_date|
        (start_date..(missing_date - 1)).reverse_each do |search_date|
          if !substitute_days.key?(missing_date) && data.key?(search_date)
Severity: Minor
Found in lib/data_feeds/pv_live_service.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

Avoid too many return statements within this method.
Open

    return series_key_as_string unless i18n_key
Severity: Major
Found in app/models/chart_data_values.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return :£ if choices.include?(:£)
    Severity: Major
    Found in app/services/charts/y_axis_selection_service.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return translate_bill_component_series(series_key_as_string) if I18n.t('advice_pages.tables.labels.bill_components').keys.map(&:to_s).include?(series_key_as_string)
      Severity: Major
      Found in app/models/chart_data_values.rb - About 30 mins to fix

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

          def self.analysis_date(meter_collection, fuel_type)
            return Time.zone.today unless fuel_type
            fuel_type = fuel_type.to_sym
            if fuel_type == :gas
              meter_collection.aggregated_heat_meters.amr_data.end_date
        Severity: Minor
        Found in app/services/aggregate_school_service.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 percent_change has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def self.percent_change(base, new_val, to_nil_if_sum_zero = false)
              return nil if to_nil_if_sum_zero && sum_data(base) == 0.0
              return 0.0 if sum_data(base) == 0.0
        
              change = (sum_data(new_val) - sum_data(base)) / sum_data(base)
        Severity: Minor
        Found in lib/energy_sparks/calculator.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 customise_y_axis has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def customise_y_axis(new_config, overrides)
            if overrides[:y_axis_units]
              overrides[:y_axis_units] = :£ if overrides[:y_axis_units] == :gb_pounds
              # not using service here as we're applying the users direct selection of axis
              valid_choices = ChartYAxisManipulation.new.y1_axis_choices(@original_config)
        Severity: Minor
        Found in app/models/customised_chart_config.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 overlapping has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def overlapping(usage_type)
            day = overlapping_days
            calendar_period = overlapping_calendar_periods
            overlapping = false
            school.school_times.each do |other|
        Severity: Minor
        Found in app/models/school_time.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