BathHacked/energy-sparks

View on GitHub

Showing 296 of 304 total issues

Class School has 79 methods (exceeds 20 allowed). Consider refactoring.
Open

class School < ApplicationRecord
  extend FriendlyId
  include EnergyTariffHolder
  include ParentMeterAttributeHolder

Severity: Major
Found in app/models/school.rb - About 1 day to fix

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

            mouseOnDay: function(e) {
              if(e.events.length > 0) {
                var content = '';
                for(var i in e.events) {
                  var startDate = e.events[i].startDate;
    Severity: Major
    Found in app/assets/javascripts/calendar_year_view.js and 1 other location - About 1 day to fix
    app/assets/javascripts/calendar_year_view.js on lines 98..119

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

    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

            mouseOnDay: function(e) {
              if(e.events.length > 0) {
                var content = '';
                for(var i in e.events) {
                  var startDate = e.events[i].startDate;
    Severity: Major
    Found in app/assets/javascripts/calendar_year_view.js and 1 other location - About 1 day to fix
    app/assets/javascripts/calendar_year_view.js on lines 152..173

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

    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

    Class ChartDataValues has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ChartDataValues
      attr_reader :anaylsis_type, :title, :subtitle, :chart1_type, :chart1_subtype,
                  :y_axis_label, :x_axis_label, :x_axis_categories, :x_max_value, :x_min_value,
                  :advice_header, :advice_footer, :y2_axis_label, :y2_point_format, :y2_max, :x_axis_ranges, :annotations,
                  :transformations, :allowed_operations, :drilldown_available, :parent_timescale_description,
    Severity: Major
    Found in app/models/chart_data_values.rb - About 7 hrs to fix

      File school.rb has 456 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'securerandom'
      
      class School < ApplicationRecord
        extend FriendlyId
        include EnergyTariffHolder
      Severity: Minor
      Found in app/models/school.rb - About 6 hrs to fix

        File application_helper.rb has 430 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        module ApplicationHelper
          include Pagy::Frontend
        
          def nice_date_times(datetime, options = {})
            return '' if datetime.nil?
        Severity: Minor
        Found in app/helpers/application_helper.rb - About 6 hrs to fix

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

            def initialize(user)
              user ||= User.new # guest user (not logged in)
              alias_action :create, :read, :update, :destroy, to: :crud
          
              # all users can do these things
          Severity: Major
          Found in app/models/ability.rb - About 6 hrs to fix

            Function commonChartOptions has 119 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function commonChartOptions(clickListener){
              return {
                colors: ["#9c3367", "#67347f", "#935fb8", "#e676a3", "#e4558b", "#7a9fb1", "#5297c6", "#97c086", "#3f7d69", "#6dc691", "#8e8d6b", "#e5c07c", "#e9d889", "#e59757", "#f4966c", "#e5644e", "#cd4851", "#bd4d65", "#515749"],
                title: { text: null },
                exporting: {
            Severity: Major
            Found in app/assets/javascripts/common_chart_options.js - About 4 hrs to fix

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

                  }else{
                    $(checkbox.data('reveals')).hide();
                    $(checkbox.data('reveals')).find('input').each(function(){
                      var input = $(this);
                      switch(input.attr('type')) {
              Severity: Major
              Found in app/assets/javascripts/form_wizard.js and 1 other location - About 4 hrs to fix
              app/assets/javascripts/form_wizard.js on lines 28..42

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 126.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

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

                  if(this.checked) {
                    $(checkbox.data('hides')).hide();
                    $(checkbox.data('hides')).find('input').each(function(){
                      var input = $(this);
                      switch(input.attr('type')) {
              Severity: Major
              Found in app/assets/javascripts/form_wizard.js and 1 other location - About 4 hrs to fix
              app/assets/javascripts/form_wizard.js on lines 53..68

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

              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

              Class BaseloadService has 35 methods (exceeds 20 allowed). Consider refactoring.
              Open

                  class BaseloadService < BaseService
                    include AnalysableMixin
              
                    def enough_data?
                      baseload_service.enough_data?
              Severity: Minor
              Found in app/services/schools/advice/baseload_service.rb - About 4 hrs to fix

                File common_chart_options.js has 337 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                Highcharts.setOptions({
                  lang: {
                    numericSymbols: null,  //otherwise by default ['k', 'M', 'G', 'T', 'P', 'E']
                    thousandsSep: ','
                  },
                Severity: Minor
                Found in app/assets/javascripts/common_chart_options.js - About 4 hrs to fix

                  File analysis.js has 337 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  "use strict";
                  
                  function updateDynamicTitles(titleWrapper, chartData) {
                    var titleH3 = titleWrapper.find('h3');
                    var titleH5 = titleWrapper.find('h5');
                  Severity: Minor
                  Found in app/assets/javascripts/analysis.js - About 4 hrs to fix

                    Class Client has 32 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                      class Client
                        class ApiFailure < StandardError; end
                        class BadRequest < StandardError; end
                        class NotFound < StandardError; end
                        class NotAllowed < StandardError; end
                    Severity: Minor
                    Found in lib/transifex/client.rb - About 4 hrs to fix

                      Class HomeController has 31 methods (exceeds 20 allowed). Consider refactoring.
                      Open

                      class HomeController < ApplicationController
                        include VideoHelper
                        include ApplicationHelper
                      
                        # **** ALL ACTIONS IN THIS CONTROLLER ARE PUBLIC! ****
                      Severity: Minor
                      Found in app/controllers/home_controller.rb - About 3 hrs to fix

                        Method invalid_row_check has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def invalid_row_check
                            @reading_data.each_with_index do |reading, index|
                              reading_date = reading[:reading_date]
                              readings = reading[:readings]
                        
                        
                        Severity: Minor
                        Found in app/models/amr_reading_data.rb - About 3 hrs 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 barColumnLine has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function barColumnLine(chartData, highchartsChart, seriesData, chartConfig) {
                          var subChartType = chartData.chart1_subtype;
                          var chartType = chartData.chart1_type;
                        
                          //console.log(chartType + ': ' + subChartType);
                        Severity: Minor
                        Found in app/assets/javascripts/common_chart_options.js - About 3 hrs 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 charge_types has 88 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def self.charge_types
                            {
                              standing_charge: {
                                units: [:day, :month, :quarter],
                                name: I18n.t('user_tariff_charge.standing_charge')
                        Severity: Major
                        Found in app/models/energy_tariff_charge.rb - About 3 hrs to fix

                          Method csv_report has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                          Open

                                def csv_report(engaged_schools)
                                  CSV.generate(headers: true) do |csv|
                                    csv << ['School Group', 'School', 'Funder', 'Country', 'Activities', 'Actions',
                                            'Programmes', 'Target?', 'Transport survey?', 'Temperatures?', 'Audit?',
                                            'Active users', 'Last visit']
                          Severity: Minor
                          Found in app/controllers/admin/reports/engaged_schools_controller.rb - About 3 hrs 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

                          Class MeterCostsTableComponent has 28 methods (exceeds 20 allowed). Consider refactoring.
                          Open

                          class MeterCostsTableComponent < ViewComponent::Base
                            # Monthly costs: a hash of Date (first day of month) => Costs::MeterMonth
                            # Change in costs: a hash of Date (first day of month) => change in total cost for month (£)
                            # id: HTML id of the table
                            # year_header: display year header row in table
                          Severity: Minor
                          Found in app/components/meter_costs_table_component.rb - About 3 hrs to fix
                            Severity
                            Category
                            Status
                            Source
                            Language