Method index
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def index
if params[:user_id] && (@user = User.find_by(login: params[:user_id]))
if current_user == @user
@challenge_signups = @user.challenge_signups.order_by_date
render action: :index and return
- 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
File challenge_signups_controller.rb
has 322 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'csv'
class ChallengeSignupsController < ApplicationController
include ExportsHelper
Class ChallengeSignupsController
has 28 methods (exceeds 20 allowed). Consider refactoring. Open
class ChallengeSignupsController < ApplicationController
include ExportsHelper
before_action :users_only, except: [:summary, :display_summary, :requests_summary]
before_action :load_collection, except: [:index]
Method request_to_array
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def request_to_array(type, request)
any_types = TagSet::TAG_TYPES.select {|type| request && request.send("any_#{type}")}
any_types.map! { |type| ts("Any %{type}", type: type.capitalize) }
tags = request.nil? ? [] : request.tag_set.tags.map {|tag| tag.name}
rarray = [(tags + any_types).join(", ")]
- 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 index
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
if params[:user_id] && (@user = User.find_by(login: params[:user_id]))
if current_user == @user
@challenge_signups = @user.challenge_signups.order_by_date
render action: :index and return
Method nested_prompt_params
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def nested_prompt_params
[
:id,
:title,
:url,
Method gift_exchange_to_csv
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def gift_exchange_to_csv
header = ["Pseud", "Email", "Sign-up URL"]
%w(request offer).each do |type|
@challenge.send("#{type.pluralize}_num_allowed").times do |i|
- 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 gift_exchange_to_csv
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def gift_exchange_to_csv
header = ["Pseud", "Email", "Sign-up URL"]
%w(request offer).each do |type|
@challenge.send("#{type.pluralize}_num_allowed").times do |i|
Method build_prompts
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def build_prompts
notice = ""
@challenge.class::PROMPT_TYPES.each do |prompt_type|
num_to_build = params["num_#{prompt_type}"] ? params["num_#{prompt_type}"].to_i : @challenge.required(prompt_type)
if num_to_build < @challenge.required(prompt_type)
- 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 prompt_meme_to_csv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def prompt_meme_to_csv
header = ["Pseud", "Sign-up URL", "Tags"]
header << "Optional Tags" if @challenge.request_restriction.optional_tags_allowed
header << "Title" if @challenge.request_restriction.title_allowed
header << "Description" if @challenge.request_restriction.description_allowed
- 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 check_pseud_ownership
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def check_pseud_ownership
if params[:challenge_signup][:pseud_id] && (pseud = Pseud.find(params[:challenge_signup][:pseud_id]))
# either you have to own the pseud, OR you have to be a mod editing after signups are closed and NOT changing the pseud
unless current_user.pseuds.include?(pseud) || (@challenge_signup && @challenge_signup.pseud == pseud && signup_closed_owner?)
flash[:error] = ts("You can't sign up with that pseud.")
- 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 destroy
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def destroy
unless @challenge.signup_open || @collection.user_is_maintainer?(current_user)
flash[:error] = ts("You cannot delete your sign-up after sign-ups are closed. Please contact a moderator for help.")
else
@challenge_signup.destroy
- 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 summary
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def summary
@summary = ChallengeSignupSummary.new(@collection)
if @collection.signups.count < (ArchiveConfig.ANONYMOUS_THRESHOLD_COUNT/2)
flash.now[:notice] = ts("Summary does not appear until at least %{count} sign-ups have been made!", count: ((ArchiveConfig.ANONYMOUS_THRESHOLD_COUNT/2)))
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
:id,
:updated_at,
:character_tagnames,
:relationship_tagnames,
:freeform_tagnames,
- Read upRead up
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 30.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76