codeforamerica/clientcomm-rails

View on GitHub

Showing 35 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

    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

        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

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

                            def report_usage(recipient, metrics, end_date)
                              @end_date = Time.zone.parse(end_date)
                              @start_date = @end_date - 7.days
                              @metrics = metrics
                              @total_outbound = 0
                          Severity: Minor
                          Found in app/mailers/notification_mailer.rb - About 1 hr to fix

                            Method create has a Cognitive Complexity of 10 (exceeds 5 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

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

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

                            function characterCount(element) {
                              if(element.length === 0) { return; }
                            
                              var
                                label = $("label[for='" + element.attr('id') + "']"),
                            Severity: Minor
                            Found in app/assets/javascripts/clientcomm.js - About 1 hr to fix
                              Severity
                              Category
                              Status
                              Source
                              Language