BathHacked/energy-sparks

View on GitHub

Showing 258 of 266 total issues

Method metered_solar has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.metered_solar
    query = <<-SQL.squish
      SELECT ma.id, m.id, s.id, s.name, solar.*
      FROM meter_attributes ma
      JOIN meters m ON ma.meter_id = m.id
Severity: Minor
Found in app/models/meter_attribute.rb - About 1 hr to fix

    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

    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

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

          def convert_to_date_to_x48_yield_hash(start_date, end_date, datetime_to_yield_hash)
            date_to_halfhour_yields_x48 = {}
            missing_date_times = []
            too_little_data_on_day = []
            interpolator = setup_interpolation(datetime_to_yield_hash)
      Severity: Minor
      Found in lib/data_feeds/pv_live_service.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

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

          $(document).on('submit','form#schools-search',function(){
            $(this).closest('#schools-content').find('.pagination').children('.page-item').removeClass('active');
          });
        Severity: Major
        Found in app/assets/javascripts/school_search.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/school_search.js on lines 15..17

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

        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

          $(document).on('submit','form#school-groups-search',function(){
            $(this).closest('#school-groups-content').find('.pagination').children('.page-item').removeClass('active');
          });
        Severity: Major
        Found in app/assets/javascripts/school_search.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/school_search.js on lines 11..13

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

        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

        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

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

              def header_groups
                [{ label: '',
                   headers: [
                     t('analytics.benchmarking.configuration.column_headings.school'),
                     t('comparisons.column_headings.recent_data')
          Severity: Minor
          Found in app/controllers/comparisons/annual_energy_use_controller.rb - About 1 hr to fix

            Method render_json has 28 lines of code (exceeds 25 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 1 hr to fix

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

                    def header_groups(fuel: true, previous_period_unadjusted: false, holiday_name: false)
                      [
                        { label: '',
                          headers: [
                            t('analytics.benchmarking.configuration.column_headings.school'),
              Severity: Minor
              Found in app/controllers/comparisons/shared/arbitrary_period_controller.rb - About 1 hr to fix

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

                    def meter_details_from_row(row)
                      if @config.lookup_by_serial_number
                        meter_serial_number = fetch_from_row(:meter_serial_number_index, row)&.strip
                        meter = find_meter_by_serial_number(meter_serial_number)
                        mpan_mprn = meter ? meter.mpan_mprn.to_s : nil
                Severity: Minor
                Found in app/services/amr/data_feed_translator.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 group_by_half_hour has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  def group_by_half_hour(school_data_array)
                    by_half_hour = Hash.new do |h1, day_type|
                      h1[day_type] = Hash.new do |h2, month|
                        h2[month] = Hash.new do |h3, half_hour|
                          h3[half_hour] = []
                Severity: Minor
                Found in app/services/calculate_average_school.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 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    def create
                      user = User.find_by_email(user_params[:email])
                      if user
                        user.add_cluster_school(@school)
                        user.add_cluster_school(user.school) unless user.school.nil?
                Severity: Minor
                Found in app/controllers/schools/cluster_admins_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 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