BathHacked/energy-sparks

View on GitHub

Showing 162 of 288 total issues

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

      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

            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

              Method country has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def country
                    scotland_postcodes = %w[AB DD DG EH FK G HS IV KA KW KY ML PA PH TD ZE]
                    wales_postcodes    = %w[CF CH GL HR LD LL NP SA SY]
                    postcode_prefix = @school.postcode.upcase[/^[[:alpha:]]+/]
              
              
              Severity: Minor
              Found in app/services/schools/country_lookup.rb - About 55 mins 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 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def export
                    CSV.generate(headers: true) do |csv|
                      csv << headers
                      @total_savings.each do |alert_type_rating, _savings| # rubocop:disable Style/HashEachMethods - not a hash
                        next unless @alert_type_rating_ids.map(&:to_i).include?(alert_type_rating.id)
              Severity: Minor
              Found in app/services/school_groups/schools_priority_action_csv_generator.rb - About 55 mins 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 to_hash has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def to_hash
                  rates = rates_attrs
                  {
                    start_date: start_date ? start_date.to_s(:es_compact) : Date.new(2000, 1, 1).to_s(:es_compact),
                    end_date: end_date ? end_date.to_s(:es_compact) : Date.new(2050, 1, 1).to_s(:es_compact),
              Severity: Minor
              Found in app/models/energy_tariff.rb - About 55 mins 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 check_operations has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_operations(chart_config)
                  allowed_operations = {}
                  OPERATIONS.each do |operation_type|
                    manipulator = ChartManagerTimescaleManipulation.factory(operation_type, chart_config, @aggregated_school)
                    allowed_operations[operation_type] = if manipulator.chart_suitable_for_timescale_manipulation?
              Severity: Minor
              Found in app/models/chart_data.rb - About 55 mins 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 with_neighbour_updates has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def with_neighbour_updates(calendar_event, attributes)
                  managing_state(calendar_event) do |pre_save, post_save|
                    calendar_event.attributes = attributes
                    reset_parent(calendar_event)
                    if calendar_event.calendar_event_type.term_time || calendar_event.calendar_event_type.holiday
              Severity: Minor
              Found in app/services/holiday_factory.rb - About 55 mins 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_area has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def process_area(area)
                    gsp_area_id = gsp_area_id(area)
                    solar_pv_data, _missing_date_times, _whole_day_substitutes = @solar_pv_tuos_interface.historic_solar_pv_data(
                      gsp_area_id,
                      area.latitude,
              Severity: Minor
              Found in lib/data_feeds/solar_pv_tuos_loader.rb - About 55 mins 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 processAnalysisOperations has a Cognitive Complexity of 8 (exceeds 5 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 45 mins 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 benchmark_colour has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def benchmark_colour(data_type, category)
                  # this has multiple fuel types
                  if [:benchmark, :benchmark_one_year].include?(@chart_type)
                    return colours_for_multiple_fuel_type_bencmark(data_type, category)
                  end
              Severity: Minor
              Found in app/models/chart_data_values.rb - About 45 mins 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 get_benchmarks_for_latest_run has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_benchmarks_for_latest_run(latest_school_runs, benchmarks)
                    latest_school_runs.each do |benchmark_result_school_generation_run|
                      school_id = benchmark_result_school_generation_run.school_id
              
                      benchmark_result_school_generation_run.benchmark_results.pluck(result_column).each do |benchmark_result|
              Severity: Minor
              Found in app/services/alerts/collate_benchmark_data.rb - About 45 mins 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_single_number_chart has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def create_single_number_chart(results, name, multiplier, series_name, y_axis_label, **kwargs)
              Severity: Minor
              Found in app/controllers/comparisons/base_controller.rb - About 45 mins to fix

                Method index has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def index
                      params[:issue_types] ||= Issue.issue_types.keys
                      params[:statuses] ||= Issue.statuses.keys
                
                      @issues = @issues.for_issue_types(params[:issue_types])
                Severity: Minor
                Found in app/controllers/admin/issues_controller.rb - About 45 mins 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 subscribe has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def subscribe(user)
                    list = @mailchimp_api.list_with_interests
                    if list
                      config = mailchimp_signup_params(user, list)
                      if config.valid?
                Severity: Minor
                Found in app/services/mailchimp_subscriber.rb - About 45 mins 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