BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

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

  class SolarPvTuosReading < ApplicationRecord
    belongs_to :solar_pv_tuos_area, foreign_key: :area_id

    scope :by_date, -> { order(:reading_date) }
    scope :since, ->(date) { where('reading_date >= ?', date) }
Severity: Minor
Found in app/models/data_feeds/solar_pv_tuos_reading.rb and 1 other location - About 30 mins to fix
app/models/data_feeds/dark_sky_temperature_reading.rb on lines 22..41

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

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 DarkSkyTemperatureReading < ApplicationRecord
    belongs_to :dark_sky_area, foreign_key: :area_id

    scope :by_date, -> { order(:reading_date) }
    scope :since, ->(date) { where('reading_date >= ?', date) }
Severity: Minor
Found in app/models/data_feeds/dark_sky_temperature_reading.rb and 1 other location - About 30 mins to fix
app/models/data_feeds/solar_pv_tuos_reading.rb on lines 27..46

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

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

    def invite_schools_to_set_first_target
      list_schools.each do |school|
        users = users(school)
        if users.any?
          TargetMailer.with_user_locales(users: users, school: school) { |mailer| mailer.first_target.deliver_now }
Severity: Minor
Found in app/services/targets/target_mailer_service.rb and 2 other locations - About 30 mins to fix
app/services/targets/target_mailer_service.rb on lines 28..33
app/services/targets/target_mailer_service.rb on lines 38..43

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

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

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

      def set_one_year_breakdown_chart
        dates = analysis_dates
        days_of_data = dates.end_date - dates.start_date
        case days_of_data
        when 1..13
Severity: Minor
Found in app/controllers/schools/advice/gas_costs_controller.rb and 1 other location - About 25 mins to fix
app/controllers/schools/advice/electricity_costs_controller.rb on lines 14..26

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

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 send
    unless @school.has_school_onboarding_event?(:onboarded_email_sent)
      users = @school.activation_users
      if users.any?
        OnboardingMailer.with_user_locales(users: users, school: @school) { |mailer| mailer.onboarded_email.deliver_now }
Severity: Minor
Found in app/services/onboarded_email_sender.rb and 1 other location - About 25 mins to fix
app/services/activation_email_sender.rb on lines 6..12

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

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 deliver
      @data_source = DataSource.find(params[:data_source_id])
      SendDataSourceReportJob.perform_later(to: current_user.email, data_source_id: @data_source.id)
      redirect_back fallback_location: admin_data_source_path(@data_source), notice: "Data source report for #{@data_source.name} requested to be sent to #{current_user.email}"
    end
Severity: Minor
Found in app/controllers/admin/data_sources_controller.rb and 1 other location - About 25 mins to fix
app/controllers/admin/procurement_routes_controller.rb on lines 26..30

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

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 deliver
      @procurement_route = ProcurementRoute.find(params[:procurement_route_id])
      SendProcurementRouteReportJob.perform_later(to: current_user.email, procurement_route_id: @procurement_route.id)
      redirect_back fallback_location: admin_procurement_route_path(@procurement_route), notice: "Procurement route report for #{@procurement_route.organisation_name} requested to be sent to #{current_user.email}"
    end
Severity: Minor
Found in app/controllers/admin/procurement_routes_controller.rb and 1 other location - About 25 mins to fix
app/controllers/admin/data_sources_controller.rb on lines 8..12

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

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

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

      def set_one_year_breakdown_chart
        dates = analysis_dates
        days_of_data = dates.end_date - dates.start_date
        case days_of_data
        when 1..13
Severity: Minor
Found in app/controllers/schools/advice/electricity_costs_controller.rb and 1 other location - About 25 mins to fix
app/controllers/schools/advice/gas_costs_controller.rb on lines 15..27

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

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 send
    unless @school.has_school_onboarding_event?(:activation_email_sent)
      users = @school.activation_users
      if users.any?
        OnboardingMailer.with_user_locales(users: users, school: @school) { |mailer| mailer.activation_email.deliver_now }
Severity: Minor
Found in app/services/activation_email_sender.rb and 1 other location - About 25 mins to fix
app/services/onboarded_email_sender.rb on lines 6..11

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

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

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

  def average_by_type_within_rank_range(by_school_type, rank_range, fuel_type)
    averages = Hash.new do |h1, school_type|
      h1[school_type] = Hash.new do |h2, day_type|
        h2[day_type] = Hash.new do |h3, month|
          h3[month] = []
Severity: Minor
Found in app/services/calculate_average_school.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 group_content has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def group_content(content)
    benchmarks = []
    i = -1
    content.each do |fragment|
      if select_fragment?(fragment)
Severity: Minor
Found in app/services/benchmark_content_filter.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 no_overlaps has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def no_overlaps
    return unless opening_time.present? && closing_time.present?

    if usage_type == 'community_use' && overlaps_school_day?
      errors.add(:overlapping_time,
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

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

  def show_data_enabled_features?
    if current_user && current_user.admin?
      params[:no_data] ? false : true
    else
      @school.data_enabled?
Severity: Minor
Found in app/controllers/concerns/school_aggregation.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 produce_csv_row_automatic has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def produce_csv_row_automatic(school_onboarding, state)
        last_event = school_onboarding.events.order(event: :desc).first
        [
          school_onboarding.school_name,
          state,
Severity: Minor
Found in app/controllers/admin/school_groups/school_onboardings_controller.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 render_json has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def render_json
    @chart_type ||= begin
      params.require(:chart_type).to_sym
    rescue => error
      render json: { error: error, status: 400 }.to_json and return
Severity: Minor
Found in app/controllers/schools/charts_controller.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 comparison_report_path has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def comparison_report_path(report, params)
    if report.reporting_period == 'custom'
      # it seems since the route doesn't use a resource polymorphic_path doesn't work
      comparisons_configurable_period_path(key: report.key, params: params)
    else
Severity: Minor
Found in app/helpers/comparisons_helper.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