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]
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]
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?
- Read upRead up
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
- Read upRead up
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?
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
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
- Read upRead up
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])
- Read upRead up
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"