Sakuten/backend

View on GitHub
api/routes/api.py

Summary

Maintainability
C
1 day
Test Coverage

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 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 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

    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 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(23)
        Severity: Major
        Found in api/routes/api.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

              Avoid too many return statements within this function.
              Open

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

                There are no issues that match your filters.

                Category
                Status