Sakuten/backend

View on GitHub

Showing 24 of 24 total issues

File api.py has 376 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from itertools import chain
from jinja2 import Environment, FileSystemLoader

from flask import Blueprint, jsonify, g, request, current_app
from api.models import Lottery, Classroom, User, Application, db, apps2members
Severity: Minor
Found in api/routes/api.py - About 5 hrs to fix

    Function login_required has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def login_required(*required_authority):
        """
            a decorder to require login
            Args:
                *required_authority (str): required authorities
    Severity: Minor
    Found in api/auth.py - 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

    Function draw_one_group_members has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def draw_one_group_members(applications, winners_num, set_just=True,
                               **kwargs):
        """internal function
            decide win (waiting) or lose for each group
        """
    Severity: Minor
    Found in api/draw.py - About 3 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

    Function apply_lottery has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def apply_lottery(idx):
        """
            apply to the lottery.
            specify the lottery id in the URL.
            1. check request errors
    Severity: Minor
    Found in api/routes/api.py - About 2 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

    Function home has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def home():
        """
            top page. Require/Check Login
        """
        if 'Content-Type' not in request.headers or \
    Severity: Minor
    Found in api/routes/auth.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 results has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def results():
        """return HTML file that contains the results of previous lotteries
            This endpoint will be used for printing PDF
            which will be put on the wall.
            whoever access here can get the file. This is not a problem because
    Severity: Minor
    Found in api/routes/api.py - 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

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

    def draw_one_normal_users(applications, winners_num, **kwargs):
        """internal function
            decide win or lose for each user not belonging to a group
            add applications to the session
        """
    Severity: Minor
    Found in api/draw.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

    Function set_status has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def set_status(self, new_status):
            if new_status not in {"pending", "waiting-pending",
                                  "won", "lose", "waiting"}:
                raise ValueError
    
    
    Severity: Minor
    Found in api/models.py - 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

    Function todays_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def todays_user(secret_id='', user_id=''):
        """confirm the user id isn't used in other day
            and return `User` object
            Args:
                secret_id (str): secret id of target user
    Severity: Minor
    Found in api/auth.py - 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 function.
    Open

        return error_response(3)  # Login unsuccessful
    Severity: Major
    Found in api/routes/auth.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return auth_error(0, 'error="invalid_token"')
      Severity: Major
      Found in api/auth.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return resp
        Severity: Major
        Found in api/routes/api.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return auth_error(0, 'realm="invalid_token"')
          Severity: Major
          Found in api/auth.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return auth_error(4, 'error="invalid_request"')
            Severity: Major
            Found in api/auth.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return jsonify(result)
              Severity: Major
              Found in api/routes/api.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return auth_error(0, 'realm="id_disabled"')
                Severity: Major
                Found in api/auth.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return error_response(23)
                  Severity: Major
                  Found in api/routes/api.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return auth_error(15, 'error="insufficient_scope"')
                    Severity: Major
                    Found in api/auth.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return jsonify(result)
                      Severity: Major
                      Found in api/routes/api.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return error_response(1)  # Invalid group member secret id
                        Severity: Major
                        Found in api/routes/api.py - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language