saasbook/esaas-engagements

View on GitHub
app/controllers/matching_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Class has too many lines. [283/250]
Open

class MatchingController < ApplicationController
  # redirects students to their engagement's preference page
  # only if they are involved in a matching in progress
  skip_before_filter :check_student
  before_action :auth_matching, except: [:show, :store]

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

File matching_controller.rb has 284 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class MatchingController < ApplicationController
  # redirects students to their engagement's preference page
  # only if they are involved in a matching in progress
  skip_before_filter :check_student
  before_action :auth_matching, except: [:show, :store]
Severity: Minor
Found in app/controllers/matching_controller.rb - About 2 hrs to fix

    Method has too many lines. [34/30]
    Open

      def create
        # check if student is already in an existing engagement
        # check if team_number is unique
        seen = []
        team_numbers = []

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [34/30]
    Open

      def create_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Cyclomatic complexity for update_engagement is too high. [9/6]
    Open

      def update_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Method has too many lines. [32/30]
    Open

      def update_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Cyclomatic complexity for create_engagement is too high. [7/6]
    Open

      def create_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

      def update_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return
    Severity: Minor
    Found in app/controllers/matching_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_engagement has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def create_engagement
        @matching = Matching.find(params[:matching_id])
        if @matching.status == 'Completed'
          redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
          return
    Severity: Minor
    Found in app/controllers/matching_controller.rb - About 1 hr to fix

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

        def create
          # check if student is already in an existing engagement
          # check if team_number is unique
          seen = []
          team_numbers = []
      Severity: Minor
      Found in app/controllers/matching_controller.rb - About 1 hr to fix

        Method update_engagement has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def update_engagement
            @matching = Matching.find(params[:matching_id])
            if @matching.status == 'Completed'
              redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
              return
        Severity: Minor
        Found in app/controllers/matching_controller.rb - About 1 hr to fix

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

            def create
              # check if student is already in an existing engagement
              # check if team_number is unique
              seen = []
              team_numbers = []
          Severity: Minor
          Found in app/controllers/matching_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_engagement has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def create_engagement
              @matching = Matching.find(params[:matching_id])
              if @matching.status == 'Completed'
                redirect_to matching_progress_path(params[:matching_id]), alert: 'Matching is already completed.'
                return
          Severity: Minor
          Found in app/controllers/matching_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 store has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def store
              @matching = Matching.find(params[:matching_id])
              @engagement = Engagement.find(params[:engagement_id])
          
              # Update last update users
          Severity: Minor
          Found in app/controllers/matching_controller.rb - About 1 hr to fix

            Method store has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

              def store
                @matching = Matching.find(params[:matching_id])
                @engagement = Engagement.find(params[:engagement_id])
            
                # Update last update users
            Severity: Minor
            Found in app/controllers/matching_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

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                      return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                    return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                    return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Unused block argument - key. If it's necessary, use _ or _key as an argument name to indicate that it won't be used.
            Open

                matching_params[:engagements_attributes].each do |key, value|

            This cop checks for unused block arguments.

            Example:

            # bad
            
            do_something do |used, unused|
              puts used
            end
            
            do_something do |bar|
              puts :foo
            end
            
            define_method(:foo) do |bar|
              puts :baz
            end

            Example:

            #good
            
            do_something do |used, _unused|
              puts used
            end
            
            do_something do
              puts :foo
            end
            
            define_method(:foo) do |_bar|
              puts :baz
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                      return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                    return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                    return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            Unused block argument - edit_user. If it's necessary, use _ or _edit_user as an argument name to indicate that it won't be used.
            Open

                @matching.last_edit_users.each do |team, edit_user|

            This cop checks for unused block arguments.

            Example:

            # bad
            
            do_something do |used, unused|
              puts used
            end
            
            do_something do |bar|
              puts :foo
            end
            
            define_method(:foo) do |bar|
              puts :baz
            end

            Example:

            #good
            
            do_something do |used, _unused|
              puts used
            end
            
            do_something do
              puts :foo
            end
            
            define_method(:foo) do |_bar|
              puts :baz
            end

            Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
            Open

                    return

            This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

            • No value is returned,
            • the block is preceded by a method chain,
            • the block has arguments,
            • the method which receives the block is not define_method or define_singleton_method,
            • the return is not contained in an inner scope, e.g. a lambda or a method definition.

            Example:

            class ItemApi
              rescue_from ValidationError do |e| # non-iteration block with arg
                return { message: 'validation error' } unless e.errors # allowed
                error_array = e.errors.map do |error| # block with method chain
                  return if error.suppress? # warned
                  return "#{error.param}: invalid" unless error.message # allowed
                  "#{error.param}: #{error.message}"
                end
                { message: 'validation error', errors: error_array }
              end
            
              def update_items
                transaction do # block without arguments
                  return unless update_necessary? # allowed
                  find_each do |item| # block without method chain
                    return if item.stock == 0 # false-negative...
                    item.update!(foobar: true)
                  end
                end
              end
            end

            There are no issues that match your filters.

            Category
            Status