codeforamerica/clientcomm-rails

View on GitHub

Showing 45 of 45 total issues

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

      Method merge_with has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def merge_with(rr_from, copy_name = false)
          ActiveRecord::Base.transaction do
            to_full_name = client.full_name
            from_full_name = rr_from.client.full_name
      
      
      Severity: Minor
      Found in app/models/reporting_relationship.rb - About 1 hr to fix

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

        function setCounter(counter, textField, modalVisible) {
          var length = $(textField).val().length;
          var fileEmpty = [undefined, ''].indexOf($('#message_attachments_0_media').val()) != -1;
          isBlank = (length == 0) && (fileEmpty);
          var tooLongForSingleText = length > 160;
        Severity: Minor
        Found in app/assets/javascripts/clientcomm.js - About 1 hr to fix

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

            def self.create_client_edit_markers(user:, phone_number:, reporting_relationships:, as_admin:)
              if as_admin && user.admin
                user_full_name = I18n.t('messages.admin_user_description')
                user_id = nil
              else
          Severity: Minor
          Found in app/models/message.rb - About 1 hr to fix

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

              def gcf_select(method, label_text, collection, notes: [], include_blank: false, prompt: false)
                <<-HTML.html_safe
                  <fieldset class="form-group#{error_state(object, method)}">
                    #{label(method, label_contents(label_text, notes))}
                    <div class="select">
            Severity: Minor
            Found in app/helpers/gcf_form_builder.rb and 1 other location - About 45 mins to fix
            app/helpers/gcf_form_builder.rb on lines 47..53

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

            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 incoming_sms_status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def incoming_sms_status
                message = Message.find_by twilio_sid: params[:SmsSid]
                return if message.nil?
            
                heroku_request_start = request.headers['X-Request-Start']
            Severity: Minor
            Found in app/controllers/twilio_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

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

              def gcf_select_fk(method, label_text, collection, notes: [], include_blank: false, prompt: false)
                <<-HTML.html_safe
                  <fieldset class="form-group#{error_state(object, method)}">
                    #{label(method, label_contents(label_text, notes))}
                    <div class="select">
            Severity: Minor
            Found in app/helpers/gcf_form_builder.rb and 1 other location - About 45 mins to fix
            app/helpers/gcf_form_builder.rb on lines 35..41

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

            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

              $('#show_note').click(function(){
                $('#full_note').show();
                $('#truncated_note').hide();
              });
            Severity: Minor
            Found in app/assets/javascripts/messages.js and 1 other location - About 40 mins to fix
            app/assets/javascripts/messages.js on lines 153..156

            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

              $('#hide_note').click(function(){
                $('#full_note').hide();
                $('#truncated_note').show();
              });
            Severity: Minor
            Found in app/assets/javascripts/messages.js and 1 other location - About 40 mins to fix
            app/assets/javascripts/messages.js on lines 148..151

            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

            Function updateMessage has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              updateMessage: function(dom_id, message_id, message_html, status_html, status) {
            Severity: Minor
            Found in app/assets/javascripts/channels/messages.js - About 35 mins to fix

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

              $(window).on('focus', function() {
                window.hasFocus = true;
                $(window).trigger('focuschange');
              });
              Severity: Minor
              Found in app/assets/javascripts/clientcomm.js and 1 other location - About 35 mins to fix
              app/assets/javascripts/clientcomm.js on lines 8..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 47.

              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

              $(window).on('blur', function() {
                window.hasFocus = false;
                $(window).trigger('focuschange');
              });
              Severity: Minor
              Found in app/assets/javascripts/clientcomm.js and 1 other location - About 35 mins to fix
              app/assets/javascripts/clientcomm.js on lines 4..7

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

              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 create has a Cognitive Complexity of 7 (exceeds 5 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 35 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 track_create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def track_create(message:, send_at:, has_attachment:)
                  if send_at.present?
                    flash[:notice] = 'Your message has been scheduled'
                    analytics_track(
                      label: 'message_scheduled',
              Severity: Minor
              Found in app/controllers/messages_controller.rb - About 35 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 handle_existing_relationship has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def handle_existing_relationship
                  return unless @client.errors.added?(:phone_number, :taken)
                  return if @conflicting_user
              
                  existing_relationship = current_user.reporting_relationships.find_by(client: @existing_client)
              Severity: Minor
              Found in app/controllers/clients_controller.rb - About 25 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 updateMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                updateMessage: function(dom_id, message_id, message_html, status_html, status) {
                  // update the message in place, if it's on the page
                  var msgElement = $("#" + dom_id);
                  if (msgElement.length) {
                    var statusElement = msgElement.find(".message--label");
              Severity: Minor
              Found in app/assets/javascripts/channels/messages.js - About 25 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 setCounter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function setCounter(counter, textField, modalVisible) {
                var length = $(textField).val().length;
                var fileEmpty = [undefined, ''].indexOf($('#message_attachments_0_media').val()) != -1;
                isBlank = (length == 0) && (fileEmpty);
                var tooLongForSingleText = length > 160;
              Severity: Minor
              Found in app/assets/javascripts/clientcomm.js - About 25 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