BathHacked/energy-sparks

View on GitHub

Showing 280 of 288 total issues

Function chart has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const chart = ( function() {

  var chartId = 'transport_surveys_pie';
  var colors = ["#5cb85c", "#ff3a5b", "#fff9b2", "#ffac21", "#3bc0f0"];

Severity: Minor
Found in app/javascript/packs/transport_surveys/charts.js - About 1 hr to fix

    Function processAnalysisOperations has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function processAnalysisOperations(chartConfig, chart, operations, drilldownAvailable, parentTimescaleDescription){
      var chartContainer = $(chart.renderTo);
      var controls = $(chartContainer).parent().find('.analysis-controls');
      var anyOperations = false;
      if(controls.length){
    Severity: Minor
    Found in app/assets/javascripts/analysis.js - About 1 hr to fix

      Method admin_user_export_csv has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.admin_user_export_csv
          CSV.generate do |csv|
            csv << [
              'School Group',
              'School',
      Severity: Minor
      Found in app/models/user.rb - About 1 hr to fix

        Method school_params has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def school_params
            params.require(:school).permit(
              :name,
              :activation_date,
              :school_type,
        Severity: Minor
        Found in app/controllers/schools_controller.rb - About 1 hr to fix

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

            if(status === 'Accepted') {
              accept.style.display = 'none';
              reject.style.display = 'inline';
              accept_msg.style.display = 'block';
              reject_msg.style.display = 'none';
          Severity: Major
          Found in app/assets/javascripts/cookie_banner.js and 1 other location - About 1 hr to fix
          app/assets/javascripts/cookie_banner.js on lines 80..85

          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

            } else {
              accept.style.display = 'inline';
              reject.style.display = 'none';
              accept_msg.style.display = 'none';
              reject_msg.style.display = 'block';
          Severity: Major
          Found in app/assets/javascripts/cookie_banner.js and 1 other location - About 1 hr to fix
          app/assets/javascripts/cookie_banner.js on lines 75..80

          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

          Method initialize has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def initialize(chart, chart_type, transformations: [], allowed_operations: {}, drilldown_available: false, parent_timescale_description: nil, y1_axis_choices: [])
              if chart
                @chart_type         = chart_type
                @chart              = chart
                @title              = chart[:title]
          Severity: Minor
          Found in app/models/chart_data_values.rb - About 1 hr to fix

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

              module ProgrammeTypes
                class ActivityTypesController < AdminController
                  def show
                    @programme_type = ProgrammeType.find(params[:programme_type_id])
            
            
            app/controllers/admin/advice_pages/activity_types_controller.rb on lines 2..18
            app/controllers/admin/advice_pages/intervention_types_controller.rb on lines 2..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 57.

            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

              module AdvicePages
                class InterventionTypesController < AdminController
                  def show
                    @advice_page = AdvicePage.find(params[:advice_page_id])
                    @intervention_type_groups_and_types = InterventionTypeGroup.listed_with_intervention_types
            app/controllers/admin/advice_pages/activity_types_controller.rb on lines 2..18
            app/controllers/admin/programme_types/activity_types_controller.rb on lines 2..21

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

            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

              module AdvicePages
                class ActivityTypesController < AdminController
                  def show
                    @advice_page = AdvicePage.find(params[:advice_page_id])
                    @activity_categories_and_types = ActivityCategory.listed_with_activity_types
            app/controllers/admin/advice_pages/intervention_types_controller.rb on lines 2..19
            app/controllers/admin/programme_types/activity_types_controller.rb on lines 2..21

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

            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 as_chart_json has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.as_chart_json(output)
                [
                  :title,
                  :subtitle,
                  :chart1_type,
            Severity: Minor
            Found in app/models/chart_data_values.rb - About 1 hr to fix

              Method for_school_group has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def self.for_school_group(school_group)
                  query = <<-SQL.squish
                    SELECT a.school_id, a.id, cv.alert_type_rating_id, vars.average_one_year_saving_£, vars.one_year_saving_co2, vars.one_year_saving_kwh
                    FROM management_priorities mp
                    INNER JOIN alert_type_rating_content_versions cv ON mp.alert_type_rating_content_version_id = cv.id
              Severity: Minor
              Found in app/models/management_priority.rb - About 1 hr to fix

                Method find_consent_grants has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                    def find_consent_grants
                      if params[:search].present?
                        search = params[:search]
                        if search['school'].present?
                          return ConsentGrant.joins(:school).where('schools.name ILIKE ?', "%#{search['school']}%").by_date
                Severity: Minor
                Found in app/controllers/admin/consent_grants_controller.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 parse_benchmark has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  def parse_benchmark(benchmark)
                    chunk = []
                    intro = []
                    keep = ''
                    benchmark.each do |fragment|
                Severity: Minor
                Found in app/services/benchmark_content_filter.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 admin_user_export_csv has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.admin_user_export_csv
                    CSV.generate do |csv|
                      csv << [
                        'School Group',
                        'School',
                Severity: Minor
                Found in app/models/user.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

                  class AnnualGasOutOfHoursUseController < BaseController
                    private
                
                    def headers
                      [
                app/controllers/comparisons/annual_electricity_out_of_hours_use_controller.rb on lines 2..38

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

                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 AnnualElectricityOutOfHoursUseController < BaseController
                    private
                
                    def headers
                      [
                app/controllers/comparisons/annual_gas_out_of_hours_use_controller.rb on lines 2..38

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

                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 funding_status has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def funding_status
                      [
                        10076,
                        100076,
                        100509,
                Severity: Minor
                Found in app/services/schools/funding_status_lookup.rb - About 1 hr to fix

                  Method funded_school_counts has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def self.funded_school_counts(visible: true, data_enabled: true)
                      query = <<-SQL.squish
                        SELECT funders.name, count(funded_schools.id)
                        FROM funders LEFT JOIN (
                          SELECT funders.id AS funder_id, schools.id AS id
                  Severity: Minor
                  Found in app/models/funder.rb - About 1 hr to fix

                    Method tx_update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def tx_update(data, locale)
                        raise 'Unexpected locale' unless I18n.available_locales.include?(locale)
                        raise 'Unexpected i18n format' unless data[locale.to_s].present? && !data[locale.to_s][resource_key].nil?
                    
                        translated_attributes = self.class.mobility_attributes.map { |attr| tx_attribute_key(attr) }
                    Severity: Minor
                    Found in app/models/concerns/transifex_serialisable.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