Showing 251 of 251 total issues
Method from_omniauth
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def from_omniauth(auth)
case auth.provider
when 'github', 'twitter', 'google_oauth2', 'facebook'
User.find_by_email auth.info.email if auth.info.email.present?
else
- 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 scan_address_field
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def self.scan_address_field(address_field)
address_field.issues.destroy_auto
if address_field.postal_or_first_address?
if address_field.value.to_s.split("\n").count < 2
address_field.issues.create title: 'issues.address_has_too_few_lines', description: 'issues.address_needs_between_2_and_4_lines', responsible_admin_id: address_field.profileable.try(:responsible_admin_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"
Further reading
Method create_special_group
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def create_special_group( group_flag, options = {} )
if find_special_group( group_flag, options )
raise ActiveRecord::RecordNotSaved, "special group :#{group_flag} already exists."
end
object_to_create = options[:parent_element].try(:child_groups)
- 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 handle_inline_attachment_uploads
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def handle_inline_attachment_uploads
if params[:inline_attachment].to_b == true
params[:attachment] ||= {}
params[:attachment][:parent_type] ||= params[:parent_type] if params[:parent_type].present?
params[:attachment][:parent_id] ||= params[:parent_id] if params[:parent_id].present?
- 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 find_object
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def find_object
@object = base.descendant_groups.find_by token: query if base.respond_to? :descendant_groups
@object ||= NavNode.where('url_component like ?', like_query).limit(1).first.try(:navable) if not params[:search_base].present? # for example "erlangen/" -- as entry point for navigation
@object ||= base.descendant_groups.where('name like ?', like_query).limit(1).first if base.respond_to? :descendant_groups
@object ||= base.descendant_pages.where('title like ?', like_query).limit(1).first if base.respond_to? :descendant_pages
- 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 text
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def text
if self.multipart?
self.parts.each do |part|
if part.text?
return part.body.decoded
- 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 events
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def events
if group
@events = group.events_with_subgroups.where(publish_on_local_website: true)
else
@events = Event.where(publish_on_global_website: true)
- 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 list_export_by_preset
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def list_export_by_preset(preset, options = {})
case preset.to_s
when 'name_list', '', nil
self.export_name_list(options)
when 'address_list'
Method restore_profile
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def restore_profile
raise "This user (#{id}) already has an existing profile. Not restoring from backup file." if profile_fields.any?
hash = ActiveSupport::JSON.decode(File.read(latest_backup_file))
if (address = hash['profile_fields'].select { |pf| pf['type'] == "ProfileFields::Address" }.first) && address['children'].present?
Method show
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
authorize! :read, group
authorize! :export_member_list, group
list_preset_i18n = I18n.translate(list_preset) if list_preset.present?
Method show
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
set_current_title group.title
set_current_navable group
set_current_tab :contacts
Identical blocks of code found in 2 locations. Consider refactoring. Open
def rights_for_dummy_users
can :read, :terms_of_use
can :accept, :terms_of_use if not read_only_mode?
can :read, User do |user| # Only read other dummy users.
- 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 53.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
def rights_for_dummy_users
can :read, :terms_of_use
can :accept, :terms_of_use if not read_only_mode?
can :read, User do |user| # Only read other dummy users.
- 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 53.
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
Method generate_dummy_user
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_dummy_user
Faker::Config.locale = Setting.preferred_locale || 'de'
user = User.new
user.first_name = Faker::Name.first_name
Method generate_public_website
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def generate_public_website
homepage = child_pages.where(type: "Pages::PublicPage").first
if not homepage
if self.subdomain.present?
domain = "#{self.subdomain}.#{AppVersion.domain}"
Method initialize
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(address_labels, options = {title: '', updated_at: Time.zone.now, sender: '', book_rate: false})
super(page_size: 'A4', top_margin: 8.mm, bottom_margin: 8.mm, left_margin: 10.mm, right_margin: 10.mm)
@document_title = options[:title]
@document_updated_at = options[:updated_at]
Method create
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
raise ActionController::ParameterMissing, 'name not given' if params[:first_name].blank? or params[:last_name].blank?
raise ActionController::ParameterMissing, 'email not given' if params[:email].blank?
raise ActionController::ParameterMissing, 'no password' if params[:password].blank?
raise ActionController::BadRequest, 'password too short' if params[:password].length < 9
Method parse
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.parse(payload, sso_secret = nil)
sso = new
sso.sso_secret = sso_secret if sso_secret
parsed = Rack::Utils.parse_query(payload)
if sso.sign(parsed["sso"]) != parsed["sig"]
Method events
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def events
if show_events?
events = show_events_for_group.try(:events) || Event.all
events = events.where(publish_on_global_website: true) if settings.show_only_events_published_on_global_website
events = events.where(publish_on_local_website: true) if settings.show_only_events_published_on_local_website
- 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 parse
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def parse(datetime, type)
return unless datetime
return datetime if datetime.respond_to?(:strftime) # already a Date/Time object -> no need to parse it
translate_month_and_day_names(datetime)
- 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"