Showing 46 of 104 total issues

File usersuite.py has 539 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Blueprint for Usersuite components
"""
from collections import OrderedDict
import logging
from datetime import datetime
Severity: Major
Found in sipa/blueprints/usersuite.py - About 1 day to fix

    File forms.py has 476 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import re
    from datetime import date
    from operator import itemgetter
    
    from flask_babel import gettext, lazy_gettext
    Severity: Minor
    Found in sipa/forms.py - About 7 hrs to fix

      User has 39 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class User(BaseUser):
          user_data: UserData
      
          def __init__(self, user_data: dict):
              try:
      Severity: Minor
      Found in sipa/model/pycroft/user.py - About 5 hrs to fix

        User has 33 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class User(BaseUser):
            def __init__(self, uid):
                super().__init__(uid)
                self.config: SampleUserData = config[uid]
                self._realname = self.config["name"]
        Severity: Minor
        Found in sipa/model/sample/user.py - About 4 hrs to fix

          File user.py has 339 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          from __future__ import annotations
          import logging
          from datetime import date
          
          from pydantic import ValidationError
          Severity: Minor
          Found in sipa/model/pycroft/user.py - About 4 hrs to fix

            File test_mail.py has 320 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            from dataclasses import dataclass, field
            from unittest import TestCase
            from unittest.mock import MagicMock, patch
            
            from sipa.mail import send_contact_mail, send_complex_mail, \
            Severity: Minor
            Found in tests/test_mail.py - About 3 hrs to fix

              File generic.py has 295 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import logging
              import os
              
              from flask import (
                  render_template,
              Severity: Minor
              Found in sipa/blueprints/generic.py - About 3 hrs to fix

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

                def data(reg_state: RegisterState):
                    form = RegisterFinishForm()
                    form.member_begin_date.min = date.today()
                    if form.validate_on_submit():
                        try:
                Severity: Minor
                Found in sipa/blueprints/register.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

                File flatpages.py has 288 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                from __future__ import annotations
                
                import logging
                from dataclasses import dataclass, field
                from functools import cached_property, lru_cache
                Severity: Minor
                Found in sipa/flatpages.py - About 2 hrs to fix

                  File user.py has 272 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  from __future__ import annotations
                  
                  import typing as t
                  # noinspection PyMethodMayBeStatic
                  from abc import ABCMeta, abstractmethod
                  Severity: Minor
                  Found in sipa/model/user.py - About 2 hrs to fix

                    PycroftApi has 23 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    class PycroftApi:
                        def __init__(self, endpoint: str, api_key: str):
                            if not endpoint.endswith("/"):
                                raise InvalidConfiguration("API endpoint must end with a '/'")
                            self._endpoint = endpoint
                    Severity: Minor
                    Found in sipa/model/pycroft/api.py - About 2 hrs to fix

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

                      def identify(reg_state: RegisterState):
                          form = RegisterIdentifyForm()
                          form.previous_dorm.choices = [_dorm_summary('', '')] + backends.dormitories_short
                      
                          suggest_skip = False
                      Severity: Minor
                      Found in sipa/blueprints/register.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 login has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def login():
                          """Login page for users
                          """
                          form = LoginForm()
                      
                      
                      Severity: Minor
                      Found in sipa/blueprints/generic.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 send_mail has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def send_mail(author: str, recipient: str, subject: str, message: str,
                                    reply_to: str = None) -> bool:
                          """Send a MIME text mail
                      
                          Send a mail from ``author`` to ``receipient`` with ``subject`` and
                      Severity: Minor
                      Found in sipa/mail.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 terminate_membership_confirm has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def terminate_membership_confirm():
                          """
                          As member, cancel your membership to a given date
                          :return:
                          """
                      Severity: Minor
                      Found in sipa/blueprints/usersuite.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 usertraffic has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def usertraffic():
                          """Show a user's traffic on a static site just as in the usersuite.
                      
                          If a user is logged but the ip corresponds to another user, a hint
                          is flashed and the traffic of the `ip_user` is displayed.
                      Severity: Minor
                      Found in sipa/blueprints/generic.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 init_env_and_config has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                      def init_env_and_config(app):
                          if not app.config.get("FLATPAGES_ROOT"):
                              app.config["FLATPAGES_ROOT"] = os.path.join(
                                  os.path.dirname(__file__),
                                  "../content",
                      Severity: Minor
                      Found in sipa/initialization.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 evaluate_status has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def evaluate_status(self, status: UserStatus):
                              message = None
                              style = None
                              if status.violation:
                                  message, style = gettext('Verstoß gegen Netzordnung'), 'danger'
                      Severity: Minor
                      Found in sipa/model/pycroft/user.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 init_app has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      def init_app(app, **kwargs):
                          """Initialize the Flask app located in the module sipa.
                          This initializes the Flask app by:
                      
                          * calling the internal init_app() procedures of each module
                      Severity: Minor
                      Found in sipa/initialization.py - About 1 hr to fix

                        Function member_request has 10 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def member_request(self, email: str, login: str, password: str,
                        Severity: Major
                        Found in sipa/model/pycroft/api.py - About 1 hr to fix
                          Severity
                          Category
                          Status
                          Source
                          Language