BathHacked/energy-sparks

View on GitHub

Showing 159 of 283 total issues

Function processAnnotations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

function processAnnotations(loaded_annotations, chart){
  var xAxis = chart.xAxis[0];
  var xAxisCategories = xAxis.categories;

  var annotations = loaded_annotations.map(function(annotation){
Severity: Minor
Found in app/assets/javascripts/analysis.js - 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 translated_series_item_for has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def translated_series_item_for(series_key_as_string)
    series_key_as_string = series_key_as_string.to_s
    return I18n.t('analytics.series_data_manager.series_name.baseload') if series_key_as_string.casecmp('baseload').zero?
    return I18n.t('advice_pages.benchmarks.benchmark_school') if series_key_as_string == 'benchmark'
    return I18n.t('advice_pages.benchmarks.exemplar_school') if series_key_as_string == 'exemplar'
Severity: Minor
Found in app/models/chart_data_values.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 current_scores has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def current_scores
    redirect_to school_group_path(@school_group) and return unless @school_group.scorable?

    setup_scores_and_years(@school_group)
    respond_to do |format|
Severity: Minor
Found in app/controllers/school_groups_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 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 to_hash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def to_hash
    rates = rates_attrs
    {
      start_date: (start_date || Date.new(2000, 1, 1)).to_fs(:es_compact),
      end_date: (end_date || Date.new(2050, 1, 1)).to_fs(:es_compact),
Severity: Minor
Found in app/models/energy_tariff.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
      user = User.find_by_email(user_params[:email])
      if user
        user.add_cluster_school(@school)
        if user.save
Severity: Minor
Found in app/controllers/schools/cluster_admins_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 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 add_bonus_points_for_included_images has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def add_bonus_points_for_included_images
    # Only add bonus points if the site wide photo bonus points is set to non zero
    return unless SiteSettings.current.photo_bonus_points&.nonzero?
    # Only add bonus points if the current observation score is non zero
    return unless self.points&.nonzero?
Severity: Minor
Found in app/models/observation.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 destroy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def destroy
    if @calendar.school? || @calendar.national?
      redirect_to admin_calendars_path, notice: 'Cannot delete national or school calendars' if @calendar.school?
    end
    if @calendar.regional? && @calendar.calendars.count > 0
Severity: Minor
Found in app/controllers/calendars_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 same_prices? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def same_prices?
      if @energy_tariff.flat_rate?
        @energy_tariff.energy_tariff_prices.first.value == @current_n3rgy_tariff[:flat_rate]
      elsif @energy_tariff.energy_tariff_prices.count == @current_n3rgy_tariff[:differential].values
        @current_n3rgy_tariff[:differential].each_value do |period|
Severity: Minor
Found in app/services/amr/n3rgy_tariff_manager.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 available_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def available_data
      return [] unless @meter.dcc_meter?
      response = api_client.consumption(@meter.mpan_mprn, @meter.fuel_type)
      return [] if response.dig('availableCacheRange', 'start').blank? &&
                   response.dig('availableCacheRange', 'end').blank?
Severity: Minor
Found in app/services/meters/n3rgy_metering_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 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 benchmark has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def self.benchmark(compare: :benchmark_school, fuel_type:)
        case compare
        when :benchmark_school
          if fuel_type == :electricity
            BenchmarkMetrics::BENCHMARK_OUT_OF_HOURS_USE_PERCENT_ELECTRICITY

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

  def send
    unless @school.has_school_onboarding_event?(:data_enabled_email_sent)
      users = @school.activation_users
      if users.any?
        target_prompt = include_target_prompt_in_email?
Severity: Minor
Found in app/services/data_enabled_email_sender.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 colours_for_multiple_fuel_type_bencmark has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def colours_for_multiple_fuel_type_bencmark(data_type, category)
    case data_type
    when translated_series_item_for('Gas')
      if benchmark_school_category?(category)
        Colours::GAS_MIDDLE
Severity: Minor
Found in app/models/chart_data_values.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 determine_target_start_date has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def determine_target_start_date
      return most_recent_target.target_date if most_recent_target.present?
      target_start_date = default_target_start_date
      [:electricity, :gas, :storage_heater].each do |fuel_type|
        service = target_service(aggregate_school, fuel_type)
Severity: Minor
Found in app/services/targets/school_target_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 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 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

Severity
Category
Status
Source
Language