BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

Method resource_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def resource_data(name, slug, project_id, categories, priority)
Severity: Minor
Found in lib/transifex/client.rb - About 35 mins to fix

    Method historic_solar_pv_data has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def historic_solar_pv_data(gsp_id, sunrise_sunset_latitude, sunrise_sunset_longitude, start_date, end_date)
    Severity: Minor
    Found in lib/data_feeds/pv_live_service.rb - About 35 mins to fix

      Method historic_month has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def historic_month(system_id, from_month, from_year, to_month, to_year)
      Severity: Minor
      Found in lib/data_feeds/geo_api.rb - About 35 mins to fix

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

          def fuel_type_names
            codes = []
            codes << I18n.t('common.electricity') if electricity_previous_period_kwh
            codes << I18n.t('common.gas') if gas_previous_period_kwh
            codes << I18n.t('common.storage_heaters') if storage_heater_previous_period_kwh
        Severity: Minor
        Found in app/models/comparison/annual_energy_use.rb and 1 other location - About 35 mins to fix
        app/models/comparison/change_in_energy_since_last_year.rb on lines 43..49

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

        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

                rescue => e
                  @errors << e
                  Rails.logger.error("#{e.message} for mpxn #{meter.mpan_mprn}, school #{meter.school.name}")
                  Rollbar.error(e, job: :dcc_withdraw_trusted_consents, mpxn: meter.mpan_mprn, school_name: meter.school.name)
                end
        Severity: Minor
        Found in app/services/meters/dcc_withdraw_trusted_consents.rb and 1 other location - About 35 mins to fix
        app/services/meters/dcc_grant_trusted_consents.rb on lines 16..20

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

        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 fuel_type_names
            codes = []
            codes << I18n.t('common.electricity') if electricity_previous_period_kwh
            codes << I18n.t('common.gas') if gas_previous_period_kwh
            codes << I18n.t('common.storage_heaters') if storage_heater_previous_period_kwh
        Severity: Minor
        Found in app/models/comparison/change_in_energy_since_last_year.rb and 1 other location - About 35 mins to fix
        app/models/comparison/annual_energy_use.rb on lines 34..40

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

        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

                rescue => e
                  @errors << e
                  Rails.logger.error("#{e.message} for mpxn #{meter.mpan_mprn}, school #{meter.school.name}")
                  Rollbar.error(e, job: :dcc_grant_trusted_consents, mpxn: meter.mpan_mprn, school_name: meter.school.name)
                end
        Severity: Minor
        Found in app/services/meters/dcc_grant_trusted_consents.rb and 1 other location - About 35 mins to fix
        app/services/meters/dcc_withdraw_trusted_consents.rb on lines 15..19

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

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

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

          def colours_for_multiple_fuel_type_benchmark(data_type, category)
            case data_type
            when translated_series_item_for('Gas')
              if benchmark_school_category?(category)
                Colours.chart_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 perform has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def perform
              ext = File.extname(path_and_file_name)
        
              content =
                if %w(.xlsx .xls).include?(ext)
        Severity: Minor
        Found in app/services/amr/data_file_parser.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 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

        Severity
        Category
        Status
        Source
        Language