openSUSE/open-build-service

View on GitHub
src/api/app/models/user.rb

Summary

Maintainability
D
2 days
Test Coverage
A
95%

Class User has 90 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < ApplicationRecord
  include CanRenderModel
  include Flipper::Identifier

  # Keep in sync with states defined in db/schema.rb
Severity: Major
Found in src/api/app/models/user.rb - About 1 day to fix

    Method has_local_permission? has a Cognitive Complexity of 13 (exceeds 8 allowed). Consider refactoring.
    Open

      def has_local_permission?(perm_string, object)
        roles = Role.ids_with_permission(perm_string)
        return false unless roles
    
        parent = nil
    Severity: Minor
    Found in src/api/app/models/user.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

    Method has_local_permission? has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def has_local_permission?(perm_string, object)
        roles = Role.ids_with_permission(perm_string)
        return false unless roles
    
        parent = nil
    Severity: Minor
    Found in src/api/app/models/user.rb - About 1 hr to fix

      Method has_local_role? has a Cognitive Complexity of 10 (exceeds 8 allowed). Consider refactoring.
      Open

        def has_local_role?(role, object)
          if object.is_a?(Package) || object.is_a?(Project)
            logger.debug "running local role package check: user #{login}, package #{object.name}, role '#{role.title}'"
            rels = object.relationships.where(role_id: role.id, user_id: id)
            return true if rels.exists?
      Severity: Minor
      Found in src/api/app/models/user.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

      Avoid too many return statements within this method.
      Open

          return true if lookup_strategy.local_permission_check(roles, object)
      Severity: Major
      Found in src/api/app/models/user.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return has_local_permission?(perm_string, parent)
        Severity: Major
        Found in src/api/app/models/user.rb - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status