BathHacked/energy-sparks

View on GitHub

Showing 296 of 304 total issues

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

export const carbon = ( function() {


  var local = {
    neutral: '',
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 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 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 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

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

        module AlertTypes
          class ActivityTypesController < AdminController
            def show
              @alert_type = AlertType.find(params[:alert_type_id])
              @rating = @alert_type.ratings.find(params[:rating_id])
      app/controllers/admin/alert_types/intervention_types_controller.rb on lines 2..22

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

      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

        module AlertTypes
          class InterventionTypesController < AdminController
            def show
              @alert_type = AlertType.find(params[:alert_type_id])
              @rating = @alert_type.ratings.find(params[:rating_id])
      app/controllers/admin/alert_types/activity_types_controller.rb on lines 2..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 72.

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

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

          def show
            weather_station_id = params[:weather_station_id]
            ordered_readings = @data_class.where(weather_station_id: weather_station_id).order(reading_date: :asc)
      
            @first_read = ordered_readings.first
      app/controllers/data_feeds/generic_controller.rb on lines 9..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 68.

      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 show
            area_id = params[:area_id]
            ordered_readings = @data_class.where(area_id: area_id).order(reading_date: :asc)
      
            @first_read = ordered_readings.first
      Severity: Major
      Found in app/controllers/data_feeds/generic_controller.rb and 1 other location - About 1 hr to fix
      app/controllers/data_feeds/weather_observations_controller.rb on lines 9..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 68.

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

          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

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

            if ('export_title' in chartConfig) {
              highchartsChart.update({
                exporting: {
                  chartOptions: {
                    allowHTML: true,
          Severity: Major
          Found in app/assets/javascripts/common_chart_options.js and 1 other location - About 1 hr to fix
          app/assets/javascripts/common_chart_options.js on lines 248..261

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

          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

            if ('export_subtitle' in chartConfig) {
              highchartsChart.update({
                exporting: {
                  chartOptions: {
                    allowHTML: true,
          Severity: Major
          Found in app/assets/javascripts/common_chart_options.js and 1 other location - About 1 hr to fix
          app/assets/javascripts/common_chart_options.js on lines 234..247

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

          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

          Function processAnnotations has 38 lines of code (exceeds 25 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 1 hr to fix

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

              class ResourceFilesController < AdminController
                load_and_authorize_resource
            
                def index
                  @resource_files = ResourceFile.order(:title)
            Severity: Major
            Found in app/controllers/admin/resource_files_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/admin/partners_controller.rb on lines 2..42

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

            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 PartnersController < AdminController
                load_and_authorize_resource
            
                def index
                  @partners = Partner.order(:position)
            Severity: Major
            Found in app/controllers/admin/partners_controller.rb and 1 other location - About 1 hr to fix
            app/controllers/admin/resource_files_controller.rb on lines 2..42

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

            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

            Severity
            Category
            Status
            Source
            Language