wearefine/fae

View on GitHub
app/controllers/fae/application_controller.rb

Summary

Maintainability
A
25 mins
Test Coverage

Class has too many lines. [102/100]
Open

  class ApplicationController < ActionController::Base
    protect_from_forgery with: :exception

    include Fae::ApplicationControllerConcern

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for authorize_model is too high. [21.1/15]
Open

    def authorize_model(model)
      return false if current_user.blank? || current_user.role.blank? || current_user.role.name.blank?

      users_role           = current_user.role.name.downcase
      tableized_model      = model.name.tableize

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for build_nav is too high. [17.72/15]
Open

    def build_nav
      return unless current_user

      # shameless green: if we continue to cache specific parts of Fae we should either:
      # - create support methods to DRY this conditional logic

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [11/10]
Open

    def build_nav
      return unless current_user

      # shameless green: if we continue to cache specific parts of Fae we should either:
      # - create support methods to DRY this conditional logic

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for authorize_model is too high. [7/6]
Open

    def authorize_model(model)
      return false if current_user.blank? || current_user.role.blank? || current_user.role.name.blank?

      users_role           = current_user.role.name.downcase
      tableized_model      = model.name.tableize

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

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

    def build_nav
      return unless current_user

      # shameless green: if we continue to cache specific parts of Fae we should either:
      # - create support methods to DRY this conditional logic
Severity: Minor
Found in app/controllers/fae/application_controller.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

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

      if request.env['HTTP_ACCEPT_LANGUAGE'].present?

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Line is too long. [88/80]
Open

      # shameless green: if we continue to cache specific parts of Fae we should either:

Line is too long. [88/80]
Open

        @fae_navigation = Rails.cache.fetch("fae_navigation_#{current_user.role.id}") do

Missing top-level class documentation comment.
Open

  class ApplicationController < ActionController::Base

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      flash.now[:warning] = 'Your changes were not saved.' if params[:cancelled].present? && params[:cancelled]== "true"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Surrounding space missing for operator ==.
Open

      flash.now[:warning] = 'Your changes were not saved.' if params[:cancelled].present? && params[:cancelled]== "true"

Checks that operators have space around them, except for ** which should not have surrounding space.

Example:

# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b

# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b

Pass &:to_s as an argument to map instead of a block.
Open

      disabled_envs = Fae.disabled_environments.map { |e| e.to_s }

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Line is too long. [128/80]
Open

      return true if role_group_for_model.blank? || (role_group_for_model.present? && role_group_for_model.include?(users_role))

Use the return of the conditional for variable assignment and comparison.
Open

      if Fae.use_cache
        @fae_navigation = Rails.cache.fetch("fae_navigation_#{current_user.role.id}") do
          Fae::Navigation.new(current_user)
        end
      else

Extra empty line detected at class body end.
Open


  end

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Line is too long. [191/80]
Open

      ActiveRecord::Base.descendants.map.reject { |m| m.name['Fae::'] || !m.instance_methods.include?(:fae_display_field) || Fae.dashboard_exclusions.include?(m.name) || !authorize_model(m) }

Line is too long. [102/80]
Open

      return false if current_user.blank? || current_user.role.blank? || current_user.role.name.blank?

Line is too long. [134/80]
Open

      redirect_to fae.root_path, flash: { error: t('fae.unauthorized_error') } unless current_user.super_admin? || current_user.admin?

Line is too long. [120/80]
Open

      flash.now[:warning] = 'Your changes were not saved.' if params[:cancelled].present? && params[:cancelled]== "true"

Line is too long. [86/80]
Open

      request.env['omniauth.origin'] || stored_location_for(resource) || fae.root_path

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

      if Fae.use_form_manager

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Line is too long. [111/80]
Open

      redirect_to fae.root_path, flash: { error: t('fae.unauthorized_error') } unless current_user.super_admin?

Unused method argument - resource_or_scope. If it's necessary, use _ or _resource_or_scope as an argument name to indicate that it won't be used. You can also write as after_sign_out_path_for(*) if you want the method to accept any arguments but don't care about them.
Open

    def after_sign_out_path_for(resource_or_scope)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Line is too long. [96/80]
Open

      render template: 'fae/pages/disabled_environment.html.slim', layout: 'fae/error.html.slim'

Line is too long. [123/80]
Open

      raise 'Fae::Navigation#structure is not defined, please define it in `app/models/concerns/fae/navigation_concern.rb`'

Line is too long. [83/80]
Open

        request.env['HTTP_ACCEPT_LANGUAGE'].scan(/[a-z-]{2,5}/i).first.try(:to_sym)

There are no issues that match your filters.

Category
Status