zammad/zammad

View on GitHub
app/models/user_device.rb

Summary

Maintainability
C
1 day
Test Coverage

Method add has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

  def self.add(user_agent, ip, user_id, fingerprint, type)

    if user_agent.blank?
      user_agent = 'unknown'
    end
Severity: Minor
Found in app/models/user_device.rb - About 4 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 add has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.add(user_agent, ip, user_id, fingerprint, type)

    if user_agent.blank?
      user_agent = 'unknown'
    end
Severity: Major
Found in app/models/user_device.rb - About 3 hrs to fix

    Method action has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.action(user_device_id, user_agent, ip, user_id, type)
        user_device = UserDevice.lookup(id: user_device_id)
    
        # update location if needed
        if user_device.ip != ip
    Severity: Minor
    Found in app/models/user_device.rb - About 45 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 action has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def self.action(user_device_id, user_agent, ip, user_id, type)
    Severity: Minor
    Found in app/models/user_device.rb - About 35 mins to fix

      Method add has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def self.add(user_agent, ip, user_id, fingerprint, type)
      Severity: Minor
      Found in app/models/user_device.rb - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status