codeforamerica/clientcomm-rails

View on GitHub

Showing 45 of 45 total issues

Method generate_reminders has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

  def self.generate_reminders(court_dates, court_locations, court_date_csv, options = {})
    time_zone_offset = '-0600' # Make sure this is by instance eventually
    total_rrs = 0
    Message.transaction do
      Rails.logger.tagged('court reminders') do
Severity: Minor
Found in app/lib/court_reminders_importer.rb - About 4 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 clientListInit has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function clientListInit() {
  var clientSearchOptions = {
    valueNames: [
      { attr: 'data-category-order', name: 'category-order' },
      { attr: 'data-fullname', name: 'fullname' },
Severity: Major
Found in app/assets/javascripts/client_search.js - About 2 hrs to fix

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

      $('#schedule-later-form').click(function() {
        checked = ($(this).find(":checkbox:checked").length > 0);
        $('#send_later').prop('disabled', !checked);
        $('#send_later').toggleClass('button--disabled', !checked);
      });
    Severity: Major
    Found in app/assets/javascripts/mass_messages.js and 1 other location - About 2 hrs to fix
    app/assets/javascripts/clients/edit.js on lines 27..31

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

    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

      $('#survey').click(function() {
        checked = ($(this).find(":checkbox:checked").length > 0);
        $('#deactivate_client').prop('disabled', !checked);
        $('#deactivate_client').toggleClass('button--disabled', !checked);
      });
    Severity: Major
    Found in app/assets/javascripts/clients/edit.js and 1 other location - About 2 hrs to fix
    app/assets/javascripts/mass_messages.js on lines 56..60

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

    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 GcfFormBuilder has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class GcfFormBuilder < ActionView::Helpers::FormBuilder
      # rubocop:disable Metrics/ParameterLists
      def gcf_input_field(method, label_text, type: 'text', notes: [], options: {}, classes: [], prefix: nil, autofocus: nil, icon: nil)
        classes = classes.append(%w[text-input])
        <<-HTML.html_safe
    Severity: Minor
    Found in app/helpers/gcf_form_builder.rb - About 2 hrs to fix

      Class Message has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class Message < ApplicationRecord
        include Rails.application.routes.url_helpers
      
        belongs_to :reporting_relationship, class_name: 'ReportingRelationship', foreign_key: 'reporting_relationship_id'
        belongs_to :original_reporting_relationship, class_name: 'ReportingRelationship', foreign_key: 'original_reporting_relationship_id'
      Severity: Minor
      Found in app/models/message.rb - About 2 hrs to fix

        Method track has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.track(distinct_id:, label:, user_agent: nil, data: {})
            if MIXPANEL_TRACKER.present?
              if user_agent
                client = DeviceDetector.new(user_agent)
                data[:client_bot_name] = client.bot_name
        Severity: Minor
        Found in app/lib/analytics_service.rb - About 2 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

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

                if(this.files[0].size > 5000000) {
                  $('span.image-help-text').text('You can only send files <5MB in size');
                  $('#file-name-preview').addClass('warning');
                  $('#image-cancel i').removeClass('icon-close').addClass('icon-warning');
                  $('#message_attachments_0_media').val('');
        Severity: Major
        Found in app/assets/javascripts/messages.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/messages.js on lines 82..99

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

        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 (!validFileType(this.files[0])) {
                $('span.image-help-text').text('You can only send .gif, .png, and .jpg files');
                $('#file-name-preview').addClass('warning');
                $('#image-cancel i').removeClass('icon-close').addClass('icon-warning');
                $('#message_attachments_0_media').val('');
        Severity: Major
        Found in app/assets/javascripts/messages.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/messages.js on lines 88..98

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

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

          def self.generate_reminders(court_dates, court_locations, court_date_csv, options = {})
            time_zone_offset = '-0600' # Make sure this is by instance eventually
            total_rrs = 0
            Message.transaction do
              Rails.logger.tagged('court reminders') do
        Severity: Minor
        Found in app/lib/court_reminders_importer.rb - About 1 hr to fix

          Method incoming_voice has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def incoming_voice
              voice_client = VoiceService.new
              client = Client.find_by(phone_number: params['From'])
              client_id = client.try(:id) || 'no client'
              department = Department.find_by(phone_number: params['To'])
          Severity: Minor
          Found in app/controllers/twilio_controller.rb - About 1 hr to fix

            Method create_from_twilio! has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.create_from_twilio!(twilio_params)
                from_phone_number = twilio_params[:From]
                to_phone_number = twilio_params[:To]
            
                department = Department.find_by(phone_number: to_phone_number)
            Severity: Minor
            Found in app/models/message.rb - About 1 hr to fix

              Method create has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def create
                  @reporting_relationship = ReportingRelationship
                                            .find_by(user: current_user.id, client_id: reporting_relationship_params['client_id'])
                  @client = Client.find(reporting_relationship_params['client_id'])
                  @transfer_reporting_relationship = ReportingRelationship.find_or_initialize_by(reporting_relationship_params)
              Severity: Minor
              Found in app/controllers/reporting_relationships_controller.rb - About 1 hr to fix

                Method create has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  def create
                    rr_current = ReportingRelationship.find_by(
                      user: current_user,
                      client: Client.find(merge_params[:client_id])
                    )
                Severity: Minor
                Found in app/controllers/merge_reporting_relationships_controller.rb - About 1 hr to fix

                  Method create has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    def create
                      send_at = if params[:commit] == 'Schedule messages'
                                  DateParser.parse(mass_message_params[:send_at][:date], mass_message_params[:send_at][:time])
                                else
                                  Time.zone.now
                  Severity: Minor
                  Found in app/controllers/mass_messages_controller.rb - About 1 hr to fix

                    Method create has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def create
                        client = current_user.clients.find params[:client_id]
                        rr = ReportingRelationship.find_by(user: current_user, client: client)
                        send_at = message_params[:send_at].present? ? DateParser.parse(message_params[:send_at][:date], message_params[:send_at][:time]) : Time.zone.now
                        valid_attachments = true
                    Severity: Minor
                    Found in app/controllers/messages_controller.rb - About 1 hr to fix

                      Method perform has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def perform(message:)
                          status_callback = Rails.application.routes.url_helpers.incoming_sms_status_url
                          return if message.sent || (message.send_at > Time.zone.now)
                      
                          message.reporting_relationship.update!(last_contacted_at: message.send_at)
                      Severity: Minor
                      Found in app/jobs/scheduled_message_job.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 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          def update
                            rr_id = params['id']
                            target_user_id = params['reporting_relationship']['user']['id']
                            transfer_note = params['transfer']['note']
                            department_id = params['reporting_relationship']['user']['department_id']
                      Severity: Minor
                      Found in app/admin/reporting_relationship.rb - About 1 hr to fix

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

                            def transfer_messages(client:, old_users:, new_user:)
                              original_rrs = ReportingRelationship.where(client: client, user: old_users)
                              original_messages = Message.where(reporting_relationship: original_rrs).scheduled
                        
                              new_rr = ReportingRelationship.find_by(client: client, user: new_user)
                        Severity: Minor
                        Found in app/admin/reporting_relationship.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 perform has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def perform(message:)
                            status_callback = Rails.application.routes.url_helpers.incoming_sms_status_url
                            return if message.sent || (message.send_at > Time.zone.now)
                        
                            message.reporting_relationship.update!(last_contacted_at: message.send_at)
                        Severity: Minor
                        Found in app/jobs/scheduled_message_job.rb - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language