Showing 143 of 144 total issues
Method fix_twitter
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def fix_twitter
if twitter
if twitter[0] == '@'
self.twitter = twitter[1..-1]
elsif m = twitter.match(/http(?:s)?:\/\/twitter.com\/(.*)/)
- 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
Complex method SingleEvent#update_event (22.7) Open
def update_event
if based_on_rule
event.schedule.add_exception_time occurrence
if event.schedule.rtimes.include? occurrence
event.schedule.remove_recurrence_time occurrence
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method ApplicationHelper#avatar_for_user (22.5) Open
def avatar_for_user(user, size = 16, class_name = nil)
if user.gravatar_email.present?
gravatar_image_tag(user.gravatar_email, title: user.nickname, alt: user.nickname, class: class_name, gravatar: { default: :identicon, size: size })
elsif user.email.present?
gravatar_image_tag(user.email, title: user.nickname, alt: user.nickname, class: class_name, gravatar: { default: :identicon, size: size })
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Event#future_single_event_creation (22.2) Open
def future_single_event_creation
self.schedule.next_occurrences(12).each do |occurrence|
if !self.schedule.extimes.map(&:to_i).include? occurrence.to_i
SingleEvent.where(event_id: self.id,
occurrence: occurrence.utc,
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method namespace(deploy)::task#setup (22.2) Open
task :setup do
on roles(:app) do
info "Creating hacken.in environment symlinks"
execute "ln -sf #{current_path}/infrastructure/uberspace/#{fetch(:stage)}/hacken-in-#{fetch(:stage)} ~/bin/"
execute "cd #{release_path}; source ~/hacken-in-#{fetch(:stage)}.secrets; bundle exec rake uberspace:print_htaccess > /var/www/virtual/hacken/#{fetch(:vhost)}/.htaccess"
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Avoid too many return
statements within this method. Open
return self.full_name.downcase <=> other.full_name.downcase
Avoid too many return
statements within this method. Open
return time_comparison
Complex method Radar::Base#fetch (21.7) Open
def fetch(start_time = Time.now)
event_ids = []
begin
next_events.each do |event|
next if event[:time] && event[:time] < start_time
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Radar::Base#update_event (21.2) Open
def update_event(event)
entry = @radar_setting.entries.find_or_create_by(entry_id: event[:id].to_s)
if (entry.entry_date != event[:time] ||
entry.previous_confirmed_content != event.except(:id, :time))
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Method create
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def create
params[:event][:schedule_rules] = JSON.parse(params[:event][:schedule_rules]) if params[:event][:schedule_rules]
params[:event][:excluded_times] = JSON.parse(params[:event][:excluded_times]) if params[:event][:excluded_times]
reconstruct_start_time
create! do |success|
- 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 css_class
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def css_class
[
(active ? "active" : false),
(has_events ? "has_events" : false),
(date == Date.today ? "today" : false)
- 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 add_missing_to_list
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def add_missing_to_list(handles, list)
handles_in_list = members(list).map(&:screen_name)
(handles - handles_in_list).each do |screen_name|
begin
request_wrapper do
- 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 6 (exceeds 5 allowed). Consider refactoring. Open
def update
params[:event][:schedule_rules] = JSON.parse(params[:event][:schedule_rules]) if params[:event][:schedule_rules]
params[:event][:excluded_times] = JSON.parse(params[:event][:excluded_times]) if params[:event][:excluded_times]
reconstruct_start_time
update! do |success|
- 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
Complex method AuthorizationsController#destroy (20.7) Open
def destroy
@auth = current_user.authorizations.find_by_id(params[:id])
if (current_user.needs_one_authorization?)
redirect_to edit_user_registration_path, notice: t('registrations.oauth.only_one_no_password')
else
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method TwitterHashTagFixer#fix_twitter (20.6) Open
def fix_twitter
if twitter
if twitter[0] == '@'
self.twitter = twitter[1..-1]
elsif m = twitter.match(/http(?:s)?:\/\/twitter.com\/(.*)/)
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Complex method Event#closest_single_event (20.4) Open
def closest_single_event(date=Date.today)
return nil if single_events.to_a.empty?
coming_up = single_events.to_a.select { |s| s.occurrence.to_date >= date }.sort_by { |s| s.occurrence }
- Read upRead up
- Exclude checks
Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.
You can read more about ABC metrics or the flog tool
Similar blocks of code found in 2 locations. Consider refactoring. Open
hash["type"] = 'weekly'
hash["interval"] = rule.validations_for(:interval).first.interval
hash["days"] = rule.validations_for(:day).map{|d| Date::DAYNAMES[d.day].downcase}
- 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 28.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
hash["type"] = 'monthly'
hash["interval"] = rule.validations_for(:day_of_week).first.occ
hash["days"] = rule.validations_for(:day_of_week).map{|d| Date::DAYNAMES[d.day].downcase}
- 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 28.
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
TODO found Open
// TODO: The following code was compiled from an old CoffeeScript file
- Exclude checks
TODO found Open
# TODO: this is a sad workaround, I could not
- Exclude checks