dxania/Send_IT_APIs

View on GitHub

Showing 27 of 46 total issues

Function edit_user has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def edit_user(user_name):
        """Modify a particular users details"""
        current_user = get_jwt_identity()
        user_input = request.get_json(force=True)        
        usermail = user_input.get("user_email")
Severity: Minor
Found in app/controllers/user_controller.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

DatabaseConnection has 26 functions (exceeds 20 allowed). Consider refactoring.
Open

class DatabaseConnection:
    def __init__(self):

#         db = 'd8l5eq5eakmkcm'
        db = 'sendit'
Severity: Minor
Found in app/controllers/db.py - About 3 hrs to fix

    Function change_present_location has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def change_present_location(parcel_id):
            """Change the present location of a parcel delivery order"""
            current_user = get_jwt_identity()
            user_input = request.get_json(force=True) 
            parcel = db.get_a_parcel(parcel_id)
    Severity: Minor
    Found in app/controllers/parcel_controller.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 validate_parcel has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_parcel(parcel):
            messages = []
            error_dict = {'message':messages}
    
            variables = ['description', 'recipient_name', 'pickup_location', 'destination', 'recipient_mobile', 'weight']
    Severity: Minor
    Found in app/validator.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 validate_status has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_status(parcel, status):
            statuses = ['pending','intransit','cancelled', 'delivered']
          
            if parcel[9] == 'cancelled' or parcel[9] == 'delivered':
                return jsonify({'message':'The parcel was either cancelled or delivered, status can not be changed'}), 400
    Severity: Minor
    Found in app/validator.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 change_parcel_destination has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def change_parcel_destination(parcel_id):
            """Change the destination of a parcel delivery order"""
            current_user = get_jwt_identity()
            user_input = request.get_json(force=True) 
            parcel = db.get_a_parcel(parcel_id)
    Severity: Minor
    Found in app/controllers/parcel_controller.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 add_parcel has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def add_parcel(self, description, user_id, user_name, recipient_name, recipient_mobile, pickup_location, destination, weight, total_price):
    Severity: Major
    Found in app/controllers/db.py - About 1 hr to fix

      Function validate_user_credentials has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def validate_user_credentials(user_name, user_email, user_password, user_mobile):
              
              if not user_email:
                  return jsonify({'message':"Email required"}), 400
              if not user_password:
      Severity: Minor
      Found in app/validator.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 sign_up has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def sign_up():
              """Register a user"""
              # db = DatabaseConnection()
              user_input = request.get_json(force=True) 
              user_name = user_input.get("user_name")          
      Severity: Minor
      Found in app/controllers/user_controller.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 get_delivery_price has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_delivery_price(weight):
              """Get total delivery price based on weight of a parcel"""
              if isinstance(weight, int):
                  # if weight<500:
                  #     delivery_price = 10000
      Severity: Minor
      Found in app/models/parcel_model.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 deeply nested control flow statements.
      Open

                              if usermail == a_user[2]:
                                  return jsonify({'message':"Email belongs to another account"}), 400
                              db.edit_user(usermail, usermobile, defaultpickup, user_name)
      Severity: Major
      Found in app/controllers/user_controller.py - About 45 mins to fix

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

            def switch_user_role(user_id):
                current_user = get_jwt_identity()
                print(current_user)
                if current_user.get('username') == 'admin':
                    user = db.get_user_by_id(user_id)
        Severity: Minor
        Found in app/controllers/user_controller.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 change_parcel_status has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def change_parcel_status(parcel_id):
                """Change the status of a parcel delivery order"""
                current_user = get_jwt_identity()
                parcel = db.get_a_parcel(parcel_id)
                if parcel:
        Severity: Minor
        Found in app/controllers/parcel_controller.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 login has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def login():
                db = DatabaseConnection()
                user_input = request.get_json(force=True)        
                username = user_input.get("user_name")
                password = user_input.get("user_password")
        Severity: Minor
        Found in app/controllers/user_controller.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 get_parcels_by_user has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_parcels_by_user(user_id):
                """Retrieve all parcels by a specific user"""
                parcel_list = []
                current_user = get_jwt_identity()
                if current_user.get('id') == user_id or current_user.get('role') == True:
        Severity: Minor
        Found in app/controllers/parcel_controller.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 jsonify({'message':'You do not have access to this'}), 401
        Severity: Major
        Found in app/controllers/user_controller.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return jsonify({'message':'User name must be letters'}), 400
          Severity: Major
          Found in app/validator.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return jsonify({'message':f"There is no parcel with ID {parcel_id}"}), 404
            Severity: Major
            Found in app/controllers/parcel_controller.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return jsonify({'message':f"There is no parcel with ID {parcel_id}"}), 404
              Severity: Major
              Found in app/controllers/parcel_controller.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return jsonify({'message':"Something went wrong"}), 400
                Severity: Major
                Found in app/controllers/user_controller.py - About 30 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language