fossasia/open-event-orga-server

View on GitHub
app/api/helpers/mail.py

Summary

Maintainability
D
2 days
Test Coverage

File mail.py has 746 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import base64
import datetime
import logging
import os
from itertools import groupby
Severity: Major
Found in app/api/helpers/mail.py - About 1 day to fix

Function send_email has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def send_email(to, action, subject, html, attachments=None, bcc=None, reply_to=None):
    """
    Sends email and records it in DB
    """
    from .tasks import get_smtp_config, send_email_task_sendgrid, send_email_task_smtp
Severity: Minor
Found in app/api/helpers/mail.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 convert_to_user_locale has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def convert_to_user_locale(
    email, date_time=None, date=None, time=None, tz=None, amount=None, currency=None
):
    """
    Convert date and time and amount to user selected language
Severity: Minor
Found in app/api/helpers/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 convert_to_user_locale has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def convert_to_user_locale(
Severity: Major
Found in app/api/helpers/mail.py - About 50 mins to fix

Function send_email has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def send_email(to, action, subject, html, attachments=None, bcc=None, reply_to=None):
Severity: Major
Found in app/api/helpers/mail.py - About 50 mins to fix

Function send_email_for_monthly_fee_payment has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def send_email_for_monthly_fee_payment(
Severity: Major
Found in app/api/helpers/mail.py - About 50 mins to fix

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

def send_email_to_attendees(order):
    attachments = None
    if current_app.config['ATTACH_ORDER_PDF']:
        attachments = [order.ticket_pdf_path, order.invoice_pdf_path]

Severity: Minor
Found in app/api/helpers/mail.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 send_email_with_action has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

def send_email_with_action(user, action, template_name, bcc=None, **kwargs):
Severity: Minor
Found in app/api/helpers/mail.py - About 35 mins to fix

Avoid too many return statements within this function.
Open

    return None
Severity: Major
Found in app/api/helpers/mail.py - About 30 mins to fix

There are no issues that match your filters.

Category
Status