extinctionrebellion/RebelsManager

View on GitHub

Showing 32 of 37 total issues

Complex method Registrations::CreateService#redirect_url (23.6)
Open

    def redirect_url
      case registration.language
      when "fr"
        "https://forms.organise.earth/index.php?r=survey/index&sid=243848&newtest=Y&Name=#{registration.name}&email=#{registration.email}"
      when "en"

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 RebelDatatable#get_raw_records (23.1)
Open

  def get_raw_records
    if user.local_group
      rebels = Rebel
        .where(local_group: user.local_group)
        .includes(:local_group, :tags, :working_groups)
Severity: Minor
Found in app/datatables/rebel_datatable.rb by flog

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 render_menu_items has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def render_menu_items(menu_items, level, options = {})
    if menu_items.present?
      ul_options = { class: ['menu', options[:class]] }
      if options[:dropdown]
        ul_options[:class] << 'dropdown'
Severity: Minor
Found in app/presenters/components/menu_presenter.rb - About 35 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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    service = Rebels::ImportService.new
    if service.run(params)
      @csv_import = service.csv_import
      if !@csv_import.import_errors.any?
Severity: Minor
Found in app/controllers/rebels/imports_controller.rb - About 35 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

Function animateCss has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  animateCss(node, animationName, callback) {
    node.classList.add('animated')
    if (animationName instanceof Array) {
      animationName.forEach((animationClass, i) => {
        node.classList.add(animationClass)
Severity: Minor
Found in app/javascript/js/animations.js - About 35 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

Complex method ApplicationDatatable::CustomOverrides#inject_conditions (23.0)
Open

    def inject_conditions(search_terms)
      search_terms.inject([]) do |crit, atom|
        search = Datatable::SimpleSearch.new(
          value: atom,
          regex: datatable.search.regexp?

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 UiHelper#callout (22.6)
Open

  def callout(type, content:, tiny: false, link_label: nil, link_href: nil, link_options: {})
    out = ActiveSupport::SafeBuffer.new
    if link_label && link_href
      out << content_tag(:div, class: "cell small-12 medium-shrink") do
        if tiny
Severity: Minor
Found in app/helpers/ui_helper.rb by flog

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

Potentially dangerous key allowed for mass assignment
Open

    )

Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

Example:

User.new(params[:user])

Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

Unprotected mass assignment near line 61: User.new(params[:user])

The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

Mass assignment is not restricted using attr_accessible

with a list of affected models.

In Rails 3.1 and newer, mass assignment can easily be disabled:

config.active_record.whitelist_attributes = true

Unfortunately, it can also easily be bypassed:

User.new(params[:user], :without_protection => true)

Brakeman will warn on uses of without_protection.

Method catch_error has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def catch_error(context: {})
    block_given? ? yield : false
  rescue => e
    Raven.capture_exception(e) if report_errors?
    Rails.logger.debug("#{e.class.name} - #{e.message}")
Severity: Minor
Found in app/services/service_base.rb - About 25 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

Complex method RebelsController#index (20.8)
Open

  def index
    respond_to do |format|
      format.csv do
        respond_to_csv_for_rebels
      end
Severity: Minor
Found in app/controllers/rebels_controller.rb by flog

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 Components::MenuPresenter#render_menu_items (20.7)
Open

  def render_menu_items(menu_items, level, options = {})
    if menu_items.present?
      ul_options = { class: ['menu', options[:class]] }
      if options[:dropdown]
        ul_options[:class] << 'dropdown'

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 DecoratorHelpers#decorate (20.0)
Open

  def decorate(model, cache: false, reload: true)
    if model.present?
      base = model.class.name.underscore.gsub("/", "__")
      decorator_class = "#{model.class.name}Decorator".constantize
      decorator_var = "@#{base}_decorator"
Severity: Minor
Found in app/decorators/decorator_helpers.rb by flog

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

Severity
Category
Status
Source
Language