zammad/zammad

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

Summary

Maintainability
B
6 hrs
Test Coverage

Method user_device_log has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

  def user_device_log(user = current_user, type = 'session')
    switched_from_user_id = ENV['SWITCHED_FROM_USER_ID'] || session[:switched_from_user_id]
    return true if %w[init mobile].include?(params[:controller]) # do no device logging on static initial page
    return true if switched_from_user_id
    return true if current_user_on_behalf # do no device logging for the user on behalf feature
Severity: Minor
Found in app/controllers/application_controller/handles_devices.rb - About 3 hrs 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 user_device_log has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def user_device_log(user = current_user, type = 'session')
    switched_from_user_id = ENV['SWITCHED_FROM_USER_ID'] || session[:switched_from_user_id]
    return true if %w[init mobile].include?(params[:controller]) # do no device logging on static initial page
    return true if switched_from_user_id
    return true if current_user_on_behalf # do no device logging for the user on behalf feature
Severity: Minor
Found in app/controllers/application_controller/handles_devices.rb - About 1 hr to fix

    Avoid too many return statements within this method.
    Open

        return true if time_to_check == false && session[:user_device_remote_ip] == remote_ip
    Severity: Major
    Found in app/controllers/application_controller/handles_devices.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

          return true if !policy(UserDevice).log?
      Severity: Major
      Found in app/controllers/application_controller/handles_devices.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

            return true if type == 'SSO'
        Severity: Major
        Found in app/controllers/application_controller/handles_devices.rb - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status