BathHacked/energy-sparks

View on GitHub

Showing 162 of 288 total issues

Class User has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < ApplicationRecord
  attribute :pupil_password, EncryptedField::Type.new

  belongs_to :school, optional: true
  belongs_to :staff_role, optional: true
Severity: Minor
Found in app/models/user.rb - About 2 hrs to fix

    Function fireRequestForJson has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function fireRequestForJson(mapDiv) {
    
      var dataUrl = '/map.json';
      var schoolGroupId = mapDiv.data('schoolGroupId');
    
    
    Severity: Major
    Found in app/assets/javascripts/map.js - About 2 hrs to fix

      Method value_for has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def value_for(recent_usage, formatted: true)
          return nil unless recent_usage
          case params['metric']
          when 'usage' then formatted ? recent_usage.usage : recent_usage.usage_text
          when 'co2' then formatted ? recent_usage.co2 : recent_usage.co2_text
      Severity: Minor
      Found in app/helpers/school_groups_helper.rb - About 2 hrs 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

      Class HeatingControlService has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class HeatingControlService
            include AnalysableMixin
      
            # number of days heating on in warm weather => rating
            WARM_WEATHER_DAYS_RATING = {
      Severity: Minor
      Found in app/services/schools/advice/heating_control_service.rb - About 2 hrs to fix

        Class SummaryTableData has 21 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class SummaryTableData
            def initialize(template_data)
              @template_data = template_data
            end
        
        
        Severity: Minor
        Found in app/classes/tables/summary_table_data.rb - About 2 hrs to fix

          Function chartSuccess has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

          function chartSuccess(chartConfig, chartData, chart) {
          
            var $chartDiv = $(chart.renderTo);
            var chartType = chartData.chart1_type;
            var seriesData = chartData.series_data;
          Severity: Minor
          Found in app/assets/javascripts/analysis.js - About 2 hrs 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 report has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def report
                report = {}
                fuel_type_report = {
                  enough_data: false,
                  recent_data: 'N/A',
          Severity: Minor
          Found in app/services/targets/school_group_targets_testing_service.rb - About 2 hrs 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 report has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def report
                report = {}
                fuel_type_report = {
                  enough_data: false,
                  recent_data: 'N/A',
          Severity: Major
          Found in app/services/targets/school_group_targets_testing_service.rb - About 2 hrs to fix

            Method csv has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def csv
                  CSV.generate(headers: true) do |csv|
                    csv << self.class.csv_headers
            
                    school_ids = School.active.pluck(:id) + School.archived.pluck(:id)
            Severity: Major
            Found in app/services/schools/funder_allocation_report_service.rb - About 2 hrs to fix

              Function carbon has 49 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export const carbon = ( function() {
              
                var local = {
                  neutral: '',
                  equivalences: '',
              Severity: Minor
              Found in app/javascript/packs/transport_surveys/carbon.js - About 1 hr to fix

                Method build_translation_search_sql has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def build_translation_search_sql(locale, query)
                      dictionary = dictionary_for(locale)
                
                      search_sql = <<-SQL.squish
                        INNER JOIN (
                Severity: Minor
                Found in app/models/concerns/searchable.rb - About 1 hr to fix

                  Method process has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def process
                      return self if @chart.nil?
                      @x_data_hash = reverse_x_data_if_required
                  
                      @series_data = []
                  Severity: Minor
                  Found in app/models/chart_data_values.rb - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method remove_users! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def remove_users!
                      raise SchoolRemover::Error.new('Cannot remove users while school is still visible') if @school.visible?
                  
                      @school.transaction do
                        @school.users.each do |user|
                  Severity: Minor
                  Found in app/services/school_remover.rb - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method create_inventory_body has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def create_inventory_body(mpxns: nil, uprns: nil, device_ids: nil)
                          body = {}
                          unless mpxns.nil?
                            body[:mpxns] = mpxns.is_a?(Array) ? mpxns : [mpxns]
                          end
                  Severity: Minor
                  Found in lib/data_feeds/n3rgy/data_api_client.rb - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method based_on_energy_use has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def based_on_energy_use(limit = NUMBER_OF_SUGGESTIONS)
                        alerts = alerts_by_fuel_type
                        fuel_types = alerts.keys
                  
                        suggestions = []
                  Severity: Minor
                  Found in app/services/recommendations/base.rb - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method column_or_bar has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def column_or_bar
                      @series_data = @x_data_hash.each_with_index.map do |(data_type, data), index|
                        data_type = tidy_label(data_type)
                        colour = work_out_best_colour(data_type)
                  
                  
                  Severity: Minor
                  Found in app/models/chart_data_values.rb - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Method series_translation_key_lookup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def series_translation_key_lookup
                      @series_translation_key_lookup ||= {
                        Series::DegreeDays::DEGREEDAYS => Series::DegreeDays::DEGREEDAYS_I18N_KEY,
                        Series::Temperature::TEMPERATURE => Series::Temperature::TEMPERATURE_I18N_KEY,
                        Series::DayType::SCHOOLDAYCLOSED => Series::DayType::SCHOOLDAYCLOSED_I18N_KEY,
                  Severity: Minor
                  Found in app/models/chart_data_values.rb - About 1 hr to fix

                    Function processAnalysisChartAjax has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function processAnalysisChartAjax(chartId, chartConfig, highchartsChart) {
                      var chartType = chartConfig.type;
                      var yAxisUnits = chartConfig.y_axis_units;
                      var mpanMprn = chartConfig.mpan_mprn;
                      var seriesBreakdown = chartConfig.series_breakdown;
                    Severity: Minor
                    Found in app/assets/javascripts/analysis.js - About 1 hr to fix

                      Method export has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def export
                            CSV.generate(headers: true) do |csv|
                              csv << headers
                              @school_group.categorise_schools.each do |fuel_type, advice_pages|
                                advice_pages.each do |advice_page_key, comparison|
                      Severity: Minor
                      Found in app/services/school_groups/comparisons_csv_generator.rb - About 1 hr to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

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

                          def perform
                            @single_reading_array.each do |single_reading|
                              # ignore rows that dont have necessary information
                              next unless single_reading[:reading_date].present? && single_reading[:mpan_mprn].present?
                      
                      
                      Severity: Minor
                      Found in app/services/amr/single_read_converter.rb - About 1 hr to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Severity
                      Category
                      Status
                      Source
                      Language