game/permissions.py
Consider simplifying this complex logical expression. Open
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())
Consider simplifying this complex logical expression. Open
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
Function can_share_level_with
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
def can_share_level_with(self, recipient, sharer):
if recipient.is_anonymous or sharer.is_anonymous:
return False
recipient_profile = recipient.userprofile
- Read upRead up
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
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:
- Read upRead up
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
Open
return can_play_or_delete_level(user, level)
Avoid too many return
statements within this function. Open
Open
return True
Avoid too many return
statements within this function. Open
Open
return user_school is not None and user_school == owner_school
Avoid too many return
statements within this function. Open
Open
return recipient_profile.student.class_field.teacher.school == sharer_profile.teacher.school
Avoid too many return
statements within this function. Open
Open
return recipient_profile.teacher.school == sharer_profile.teacher.school
Avoid too many return
statements within this function. Open
Open
return False
Avoid too many return
statements within this function. Open
Open
return level.default and not level.episode.in_development