bikeindex/bike_index

View on GitHub
app/controllers/concerns/controller_helpers.rb

Summary

Maintainability
B
4 hrs
Test Coverage
C
75%

Method authenticate_user has a Cognitive Complexity of 17 (exceeds 10 allowed). Consider refactoring.
Open

  def authenticate_user(translation_key: nil, translation_args: {}, flash_type: :error)
    translation_key ||= :you_have_to_log_in

    # Make absolutely sure the current user is confirmed - mainly for testing
    if current_user&.confirmed?
Severity: Minor
Found in app/controllers/concerns/controller_helpers.rb - About 1 hr 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

Consider simplifying this complex logical expression.
Open

    if session[:return_to].present? || cookies[:return_to].present? || params[:return_to]
      # NOTE: This is duplicated in permitted_return_to
      target = session[:return_to] || cookies[:return_to] || params[:return_to]
      session[:return_to] = nil
      cookies[:return_to] = nil
Severity: Critical
Found in app/controllers/concerns/controller_helpers.rb - About 1 hr to fix

    Method set_period has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
    Open

      def set_period
        @timezone ||= Time.zone
        # Set time period
        @period ||= params[:period]
        if @period == "custom"
    Severity: Minor
    Found in app/controllers/concerns/controller_helpers.rb - About 1 hr 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

    Avoid too many return statements within this method.
    Open

          redirect_to(discourse_authentication_url) && (return true)
    Severity: Major
    Found in app/controllers/concerns/controller_helpers.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

              redirect_to(new_session_url(partner: sign_in_partner)) && return
      Severity: Major
      Found in app/controllers/concerns/controller_helpers.rb - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status