TeaWithStrangers/tws-on-rails

View on GitHub

Showing 35 of 35 total issues

Class TeaTime has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

class TeaTime < ActiveRecord::Base
  # Only soft-delete tea times
  acts_as_paranoid

  validates_presence_of :host, :start_time, :city, :duration
Severity: Minor
Found in app/models/tea_time.rb - About 4 hrs to fix

    Class User has 27 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class User < ActiveRecord::Base
      acts_as_paranoid
    
      # Include default devise modules. Others available are:
      # :confirmable, :lockable, :timeoutable and :omniauthable
    Severity: Minor
    Found in app/models/user.rb - About 3 hrs to fix

      Method create has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          @user = current_user
          @tea_time = TeaTime.find(params[:id])
      
          @attendance = Attendance.where(tea_time_id: @tea_time.id, user_id: @user.id).first_or_initialize
      Severity: Minor
      Found in app/controllers/attendance_controller.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 mark has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def mark
          @tea_time = TeaTime.find(params[:id])
          respond_to do |format|
            case params[:marking]
            when 'email'
      Severity: Minor
      Found in app/controllers/attendance_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 create has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          if params[:referral] == false
            super
          else
            user_info = GetOrCreateNonWaitlistedUser.call(user_params)
      Severity: Minor
      Found in app/controllers/registrations_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 sync_user has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.sync_user(user, new_record = false)
          # Ensure the user is not deleted
          if @sg and !user.deleted_at
            # When a user email changes, we delete the old recipient record
            # Then we can insert the new one with the updated email
      Severity: Minor
      Found in app/services/send_grid_list.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 create_list_from_segments has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.create_list_from_segments(name, segments, sample)
          # Creates a SendGrid List corresponding to the union of the segments in
          # `segments` and with a random sample of `sample` (which can be blank).
          if @sg
            all_recipients = get_recipients(segments).to_a
      Severity: Minor
      Found in app/services/send_grid_list.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 create_list_from_segments has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.create_list_from_segments(name, segments, sample)
          # Creates a SendGrid List corresponding to the union of the segments in
          # `segments` and with a random sample of `sample` (which can be blank).
          if @sg
            all_recipients = get_recipients(segments).to_a
      Severity: Minor
      Found in app/services/send_grid_list.rb - About 1 hr to fix

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

          $('#tea-time-month-next').on('click', function(e) {
            e.preventDefault();
            $(this).closest('.month-display-container').removeClass('show-left').addClass('show-right');
          });
        Severity: Major
        Found in app/assets/javascripts/tea_times.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/tea_times.js on lines 10..13

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

        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

          $('#tea-time-month-prev').on('click', function(e) {
            e.preventDefault();
            $(this).closest('.month-display-container').removeClass('show-right').addClass('show-left');
          });
        Severity: Major
        Found in app/assets/javascripts/tea_times.js and 1 other location - About 1 hr to fix
        app/assets/javascripts/tea_times.js on lines 5..8

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

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

          def followup(tea_time_id, attendances, status)
            sendgrid_category "Tea Time Post-Attendance Followup: #{status}"
        
            @tea_time = TeaTime.find(tea_time_id)
        
        
        Severity: Minor
        Found in app/mailers/tea_time_mailer.rb - About 1 hr to fix

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

            def filter_tea_times(tea_times, next_month = false)
              # Return an array of tea times filtered based on this select block.
              tea_times.select { |tt|
                if tt.city.nil? or tt.city.timezone.blank?
                  # If no city or city timezone information, include by default
          Severity: Minor
          Found in app/controllers/tea_times_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 mark has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def mark
              @tea_time = TeaTime.find(params[:id])
              respond_to do |format|
                case params[:marking]
                when 'email'
          Severity: Minor
          Found in app/controllers/attendance_controller.rb - About 1 hr to fix

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

              def create
                @user = current_user
                @tea_time = TeaTime.find(params[:id])
            
                @attendance = Attendance.where(tea_time_id: @tea_time.id, user_id: @user.id).first_or_initialize
            Severity: Minor
            Found in app/controllers/attendance_controller.rb - About 1 hr to fix

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

                def send_mail
                  # THE FORM DOESN'T PASS IN A TO FIELD, so that is always set to default
                  opts = {
                    subject:  params[:mass_mail][:subject],
                    body:     params[:mass_mail][:body],
              Severity: Minor
              Found in app/controllers/admin_controller.rb - About 1 hr to fix

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

                var shareBootstrap = function() {
                  // Set click behavior of the "Try This On For Size" button
                  $('.sharing-try-button').on('click', function(e) {
                    // Advance share item index
                    currentShareItem++;
                Severity: Minor
                Found in app/assets/javascripts/share.js - About 1 hr to fix

                  Function shareBootstrap has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                  var shareBootstrap = function() {
                    // Set click behavior of the "Try This On For Size" button
                    $('.sharing-try-button').on('click', function(e) {
                      // Advance share item index
                      currentShareItem++;
                  Severity: Minor
                  Found in app/assets/javascripts/share.js - 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 create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def create
                      if user_signed_in?
                        city              = City.new(params.require(:city).permit(:name))
                        city.timezone     = "Pacific Time (US & Canada)" if !city.timezone
                        city.city_code    = CityCodeGenerator.generate if !city.city_code
                  Severity: Minor
                  Found in app/controllers/api/v1/cities_controller.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 send_mail has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def send_mail
                      # THE FORM DOESN'T PASS IN A TO FIELD, so that is always set to default
                      opts = {
                        subject:  params[:mass_mail][:subject],
                        body:     params[:mass_mail][:body],
                  Severity: Minor
                  Found in app/controllers/admin_controller.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 add_to_unsubscribe_group has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def self.add_to_unsubscribe_group(email)
                      if @sg
                        data = {'recipient_emails': [email]}
                        response = @sg.client.asm.groups._(ENV['SENDGRID_NEWSLETTER_UNSUB_GROUP']).suppressions.post(request_body: data)
                        if response.status_code == '201'
                  Severity: Minor
                  Found in app/services/send_grid_list.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

                  Severity
                  Category
                  Status
                  Source
                  Language