ocadotechnology/rapid-router

View on GitHub
game/permissions.py

Summary

Maintainability
C
1 day
Test Coverage

Consider simplifying this complex logical expression.
Open

        if (
            hasattr(sharer_profile, "student")
            and not (sharer_profile.student.is_independent())
            and hasattr(recipient_profile, "student")
            and not (recipient_profile.student.is_independent())
Severity: Critical
Found in game/permissions.py - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        if not user.is_anonymous and hasattr(user.userprofile, "student") and user.userprofile.student.class_field:
            # If the user is a student, check that the level isn't locked for their class
            return user.userprofile.student.class_field not in level.locked_for_class.all()
        elif level.default and not level.episode.in_development:
            return True
    Severity: Critical
    Found in game/permissions.py - About 1 hr to fix

      Function can_share_level_with has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def can_share_level_with(self, recipient, sharer):
              if recipient.is_anonymous or sharer.is_anonymous:
                  return False
      
              recipient_profile = recipient.userprofile
      Severity: Minor
      Found in game/permissions.py - 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

      Function can_play_level has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def can_play_level(user, level, early_access):
          if not user.is_anonymous and hasattr(user.userprofile, "student") and user.userprofile.student.class_field:
              # If the user is a student, check that the level isn't locked for their class
              return user.userprofile.student.class_field not in level.locked_for_class.all()
          elif level.default and not level.episode.in_development:
      Severity: Minor
      Found in game/permissions.py - 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

      Avoid too many return statements within this function.
      Open

              return can_play_or_delete_level(user, level)
      Severity: Major
      Found in game/permissions.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return True
        Severity: Major
        Found in game/permissions.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return user_school is not None and user_school == owner_school
          Severity: Major
          Found in game/permissions.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return recipient_profile.student.class_field.teacher.school == sharer_profile.teacher.school
            Severity: Major
            Found in game/permissions.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return recipient_profile.teacher.school == sharer_profile.teacher.school
              Severity: Major
              Found in game/permissions.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return False
                Severity: Major
                Found in game/permissions.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return level.default and not level.episode.in_development
                  Severity: Major
                  Found in game/permissions.py - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status