BathHacked/energy-sparks

View on GitHub

Showing 280 of 288 total issues

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

  def rates_attrs
    attrs = {}
    if flat_rate?
      if (first_price = energy_tariff_prices.first)
        attrs[:flat_rate] = { rate: first_price.value.to_s, per: first_price.units.to_s }
Severity: Minor
Found in app/models/energy_tariff.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 update has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    super do |resource|
      @allow_newsletters = allow_newletters?(resource)
      @allow_alerts = allow_alerts?(resource)
      @subscribe_alerts = auto_create_alert_contact?
Severity: Minor
Found in app/controllers/passwords_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 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 validate_each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(record, attr_name, value)
    options.slice(*COMPARE_CHECKS.keys).each do |option, raw_option_value|
      option_value = resolve_value(record, raw_option_value)

      if value.nil? || value.blank?
Severity: Minor
Found in app/validators/comparison_validator.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

Function setupAnalysisControls has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function setupAnalysisControls(chartContainer, chartConfig){
  var controls = $(chartContainer).parent().find('.analysis-controls');
  if(controls.length){
    controls.find('.move_back').on('click', function(event){
      event.preventDefault();
Severity: Minor
Found in app/assets/javascripts/analysis.js - About 1 hr to fix

    Method render_json has 27 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

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

            def create
              @school_group.meter_attributes.create!(
                attribute_type: params[:attribute][:type],
                reason: params[:attribute][:reason],
                input_data: params[:attribute][:root],
      app/controllers/admin/schools/school_attributes_controller.rb on lines 18..29

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

      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 school_procurement_route_report
          to, procurement_route_id = params.values_at(:to, :procurement_route_id)
          @procurement_route = ProcurementRoute.find(procurement_route_id)
          title = "#{t('common.application')}-#{@procurement_route.organisation_name}-meters-#{Time.zone.now.iso8601}".parameterize
          attachments[(title + '.csv')] = { mime_type: 'text/csv', content: @procurement_route.to_csv }
      Severity: Major
      Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
      app/mailers/admin_mailer.rb on lines 5..11

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

      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 create
              @school.meter_attributes.create!(
                attribute_type: params[:attribute][:type],
                reason: params[:attribute][:reason],
                input_data: params[:attribute][:root],
      app/controllers/admin/school_groups/meter_attributes_controller.rb on lines 16..27

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

      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 school_data_source_report
          to, data_source_id = params.values_at(:to, :data_source_id)
          @data_source = DataSource.find(data_source_id)
          title = "#{t('common.application')}-#{@data_source.name}-meters-#{Time.zone.now.iso8601}".parameterize
          attachments[(title + '.csv')] = { mime_type: 'text/csv', content: @data_source.to_csv }
      Severity: Major
      Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
      app/mailers/admin_mailer.rb on lines 14..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 49.

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

          def school_params
            params.require(:school).permit(
              :indicated_has_solar_panels,
              :indicated_has_storage_heaters,
              :has_swimming_pool,
      Severity: Minor
      Found in app/controllers/schools/your_school_estates_controller.rb - About 1 hr to fix

        Function initChart has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          function initChart(chartDiv) {
        
            var supply = $(chartDiv).find("input[name='supply']").val();
            var period = $(chartDiv).find("input[name='period']").val();
        
        
        Severity: Minor
        Found in app/assets/javascripts/usage_charts.js - About 1 hr to fix

          Method resource_data has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def resource_data(name, slug, project_id, categories, priority)
                {
                  "data": {
                    "attributes": {
                      "accept_translations": true,
          Severity: Minor
          Found in lib/transifex/client.rb - About 1 hr to fix

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

              module System
                class MissingElectricityData
                  def self.front_end_template_variables
                    {}
                  end
            Severity: Major
            Found in app/services/alerts/system/missing_electricity_data.rb and 1 other location - About 1 hr to fix
            app/services/alerts/system/missing_gas_data.rb on lines 2..28

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

            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 sort_out_dates_when_tidying_labels(current_label)
                date_to_and_from = current_label.scan(/\d+|[A-Za-z]+/).drop(1).each_slice(4).to_a
            
                if date_to_and_from.size > 1 && date_to_and_from[0][3] != date_to_and_from[1][3]
                  date_to_and_from[0].delete_at(0)
            Severity: Major
            Found in app/models/chart_data_values.rb and 1 other location - About 1 hr to fix
            app/helpers/application_helper.rb on lines 243..250

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

            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 System
                class MissingGasData
                  def self.front_end_template_variables
                    {}
                  end
            Severity: Major
            Found in app/services/alerts/system/missing_gas_data.rb and 1 other location - About 1 hr to fix
            app/services/alerts/system/missing_electricity_data.rb on lines 2..28

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

            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 bulk_update_meter_procurement_route
                    meters = @school_group.meters.where(meter_type: meter_types)
                    if meters.update_all(procurement_route_id: meter_update_params['procurement_route_id']&.to_i)
                      notice = "Procurement route for #{meters.count} #{meter_types.to_sentence} #{'meter'.pluralize(meters.count)} successfully updated for this school group."
                      redirect_to(admin_school_group_meter_updates_path(@school_group), notice: notice) and return
            app/controllers/admin/school_groups/meter_updates_controller.rb on lines 9..16

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

            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 sort_out_dates_when_tidying_labels(current_label)
                date_to_and_from = current_label.scan(/\d+|[A-Za-z]+/).drop(1).each_slice(4).to_a
            
                if date_to_and_from.size > 1 && date_to_and_from[0][3] != date_to_and_from[1][3]
                  date_to_and_from[0].delete_at(0)
            Severity: Major
            Found in app/helpers/application_helper.rb and 1 other location - About 1 hr to fix
            app/models/chart_data_values.rb on lines 468..475

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

            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 bulk_update_meter_data_source
                    meters = @school_group.meters.where(meter_type: meter_types)
                    if meters.update_all(data_source_id: meter_update_params['data_source_id']&.to_i)
                      notice = "Data source for #{meters.count} #{meter_types.to_sentence} #{'meter'.pluralize(meters.count)} successfully updated for this school group."
                      redirect_to(admin_school_group_meter_updates_path(@school_group), notice: notice) and return
            app/controllers/admin/school_groups/meter_updates_controller.rb on lines 19..26

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

            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

            Consider simplifying this complex logical expression.
            Open

                if can?(:show_management_dash, @school)
                  @add_contacts = site_settings.message_for_no_contacts && @school.contacts.empty? && can?(:manage, Contact)
                  @add_pupils = site_settings.message_for_no_pupil_accounts && @school.users.pupil.empty? && can?(:manage_users, @school)
                  @prompt_training = @show_data_enabled_features && current_user.confirmed_at > 30.days.ago
                  @prompt_for_bill = @school.bill_requested && can?(:index, ConsentDocument)
            Severity: Major
            Found in app/controllers/schools_controller.rb - About 1 hr to fix
              Severity
              Category
              Status
              Source
              Language