sharetribe/sharetribe

View on GitHub
app/controllers/listings_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

File listings_controller.rb has 393 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class ListingsController < ApplicationController
  class ListingDeleted < StandardError; end

  # Skip auth token check as current jQuery doesn't provide it automatically
  skip_before_action :verify_authenticity_token, :only => [:close, :update, :follow, :unfollow]
Severity: Minor
Found in app/controllers/listings_controller.rb - About 5 hrs to fix

    Class ListingsController has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class ListingsController < ApplicationController
      class ListingDeleted < StandardError; end
    
      # Skip auth token check as current jQuery doesn't provide it automatically
      skip_before_action :verify_authenticity_token, :only => [:close, :update, :follow, :unfollow]
    Severity: Minor
    Found in app/controllers/listings_controller.rb - About 4 hrs to fix

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

        def create
          if new_listing_author != @current_user
            logger.info "ADMIN ACTION: admin='#{@current_user.id}' create listing params=#{params.inspect}"
          end
          if show_location? && params[:listing][:origin_loc_attributes][:address].blank?
      Severity: Minor
      Found in app/controllers/listings_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 update has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def update
          if (params[:listing][:origin] && (params[:listing][:origin_loc_attributes][:address].empty? || params[:listing][:origin].blank?))
            params[:listing].delete("origin_loc_attributes")
            if @listing.origin_loc
              @listing.origin_loc.delete
      Severity: Minor
      Found in app/controllers/listings_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 create has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create
          if new_listing_author != @current_user
            logger.info "ADMIN ACTION: admin='#{@current_user.id}' create listing params=#{params.inspect}"
          end
          if show_location? && params[:listing][:origin_loc_attributes][:address].blank?
      Severity: Minor
      Found in app/controllers/listings_controller.rb - About 1 hr to fix

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

          def update
            if (params[:listing][:origin] && (params[:listing][:origin_loc_attributes][:address].empty? || params[:listing][:origin].blank?))
              params[:listing].delete("origin_loc_attributes")
              if @listing.origin_loc
                @listing.origin_loc.delete
        Severity: Minor
        Found in app/controllers/listings_controller.rb - About 1 hr to fix

          Method is_authorized_to_post has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def is_authorized_to_post
              if new_listing_author != @current_user
                unless @current_user.has_admin_rights?(@current_community)
                  flash[:error] = t("layouts.notifications.you_are_not_authorized_to_do_this")
                  redirect_to root_path
          Severity: Minor
          Found in app/controllers/listings_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 ensure_authorized_to_view has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def ensure_authorized_to_view
              # If listing is not found (in this community) the find method
              # will throw ActiveRecord::NotFound exception, which is handled
              # correctly in production environment (404 page)
              @listing = @current_community.listings.find(params[:id])
          Severity: Minor
          Found in app/controllers/listings_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

          There are no issues that match your filters.

          Category
          Status