opf/openproject

View on GitHub
app/services/authorization/user_permissible_service.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Method allowed_in_any_entity? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def allowed_in_any_entity?(permission, entity_class, in_project: nil) # rubocop:disable Metrics/PerceivedComplexity
      perms = contextual_permissions(permission, context_name(entity_class))
      return false unless authorizable_user?
      return false if in_project && !(in_project.active? || in_project.being_archived?)
      return true if admin_and_all_granted_to_admin?(perms)
Severity: Minor
Found in app/services/authorization/user_permissible_service.rb - About 55 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 allowed_in_single_entity? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def allowed_in_single_entity?(permissions, entity)
      return false if entity.nil?
      return false if entity.project.nil?
      return false unless entity.project.active? || entity.project.being_archived?

Severity: Minor
Found in app/services/authorization/user_permissible_service.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 admin_and_all_granted_to_admin?(permissions)
Severity: Major
Found in app/services/authorization/user_permissible_service.rb - About 30 mins to fix

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

        def allowed_in_single_project?(permissions, project)
          return false if project.nil?
          return false unless project.active? || project.being_archived?
    
          permissions_filtered_for_project = permissions_by_enabled_project_modules(project, permissions)
    Severity: Minor
    Found in app/services/authorization/user_permissible_service.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

    There are no issues that match your filters.

    Category
    Status