myems-api/core/emailmessage.py

Summary

Maintainability
F
1 wk
Test Coverage

File emailmessage.py has 414 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re
from datetime import datetime, timedelta, timezone
import falcon
import mysql.connector
import simplejson as json
Severity: Minor
Found in myems-api/core/emailmessage.py - About 5 hrs to fix

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

        def on_put(req, resp, id_):
            """Handles PUT requests"""
            admin_control(req)
    
            if not id_.isdigit() or int(id_) <= 0:
    Severity: Minor
    Found in myems-api/core/emailmessage.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 on_post has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_post(req, resp):
            """Handles POST requests"""
            admin_control(req)
            try:
                upload = req.get_param('file')
    Severity: Minor
    Found in myems-api/core/emailmessage.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 on_get has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_get(req, resp):
            admin_control(req)
            print(req.params)
            start_datetime_local = req.params.get('startdatetime')
            end_datetime_local = req.params.get('enddatetime')
    Severity: Minor
    Found in myems-api/core/emailmessage.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 on_put has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def on_put(req, resp, id_):
            """Handles PUT requests"""
            admin_control(req)
    
            if not id_.isdigit() or int(id_) <= 0:
    Severity: Minor
    Found in myems-api/core/emailmessage.py - About 1 hr to fix

      Function on_post has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def on_post(req, resp):
              """Handles POST requests"""
              admin_control(req)
              try:
                  upload = req.get_param('file')
      Severity: Minor
      Found in myems-api/core/emailmessage.py - About 1 hr to fix

        Function on_delete has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def on_delete(req, resp, id_):
                admin_control(req)
                if not id_.isdigit() or int(id_) <= 0:
                    raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                           description='API.INVALID_EMAIL_MESSAGE_ID')
        Severity: Minor
        Found in myems-api/core/emailmessage.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 on_get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def on_get(req, resp, id_):
                admin_control(req)
                if not id_.isdigit() or int(id_) <= 0:
                    raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                           description='API.INVALID_EMAIL_MESSAGE_ID')
        Severity: Minor
        Found in myems-api/core/emailmessage.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

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

            @staticmethod
            @user_logger
            def on_delete(req, resp, id_):
                admin_control(req)
                if not id_.isdigit() or int(id_) <= 0:
        Severity: Major
        Found in myems-api/core/emailmessage.py and 3 other locations - About 1 day to fix
        myems-api/core/textmessage.py on lines 426..456
        myems-api/core/user.py on lines 1519..1551
        myems-api/core/wechatmessage.py on lines 475..507

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 210.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                result = {"id": row[0],
                          "recipient_name": row[1],
                          "recipient_email": row[2],
                          "subject": row[3],
                          "message": row[4].replace("<br>", ""),
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 1 day to fix
        myems-api/core/emailmessage.py on lines 81..90

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 140.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        meta_result = {"id": row[0],
                                       "recipient_name": row[1],
                                       "recipient_email": row[2],
                                       "subject": row[3],
                                       "message": row[4].replace("<br>", ""),
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 1 day to fix
        myems-api/core/emailmessage.py on lines 278..286

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 140.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 7 locations. Consider refactoring.
        Open

                if 'status' not in new_values['data'].keys() or \
                        not isinstance(new_values['data']['status'], str) or \
                        len(str.strip(new_values['data']['status'])) == 0 or \
                        str.strip(new_values['data']['status']) not in ('new', 'acknowledged', 'timeout'):
                    raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
        Severity: Major
        Found in myems-api/core/emailmessage.py and 6 other locations - About 1 day to fix
        myems-api/core/notification.py on lines 274..278
        myems-api/core/textmessage.py on lines 327..331
        myems-api/core/user.py on lines 1434..1438
        myems-api/core/webmessage.py on lines 300..304
        myems-api/core/webmessage.py on lines 526..530
        myems-api/core/wechatmessage.py on lines 375..379

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 123.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 19 locations. Consider refactoring.
        Open

                if 'rule_id' in new_values['data'].keys():
                    if new_values['data']['rule_id'] <= 0:
                        raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                               description='API.INVALID_RULE_ID')
                    rule_id = new_values['data']['rule_id']
        Severity: Major
        Found in myems-api/core/emailmessage.py and 18 other locations - About 4 hrs to fix
        myems-api/core/emailmessage.py on lines 116..122
        myems-api/core/shopfloor.py on lines 115..121
        myems-api/core/shopfloor.py on lines 123..129
        myems-api/core/shopfloor.py on lines 371..377
        myems-api/core/shopfloor.py on lines 379..385
        myems-api/core/shopfloor.py on lines 2204..2210
        myems-api/core/shopfloor.py on lines 2212..2218
        myems-api/core/space.py on lines 131..137
        myems-api/core/space.py on lines 166..172
        myems-api/core/space.py on lines 174..180
        myems-api/core/space.py on lines 547..553
        myems-api/core/space.py on lines 3970..3976
        myems-api/core/space.py on lines 4005..4011
        myems-api/core/space.py on lines 4013..4019
        myems-api/core/textmessage.py on lines 106..112
        myems-api/core/textmessage.py on lines 291..297
        myems-api/core/wechatmessage.py on lines 110..116
        myems-api/core/wechatmessage.py on lines 318..324

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 84.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 19 locations. Consider refactoring.
        Open

                if 'rule_id' in new_values['data'].keys():
                    if new_values['data']['rule_id'] <= 0:
                        raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                               description='API.INVALID_RULE_ID')
                    rule_id = new_values['data']['rule_id']
        Severity: Major
        Found in myems-api/core/emailmessage.py and 18 other locations - About 4 hrs to fix
        myems-api/core/emailmessage.py on lines 316..322
        myems-api/core/shopfloor.py on lines 115..121
        myems-api/core/shopfloor.py on lines 123..129
        myems-api/core/shopfloor.py on lines 371..377
        myems-api/core/shopfloor.py on lines 379..385
        myems-api/core/shopfloor.py on lines 2204..2210
        myems-api/core/shopfloor.py on lines 2212..2218
        myems-api/core/space.py on lines 131..137
        myems-api/core/space.py on lines 166..172
        myems-api/core/space.py on lines 174..180
        myems-api/core/space.py on lines 547..553
        myems-api/core/space.py on lines 3970..3976
        myems-api/core/space.py on lines 4005..4011
        myems-api/core/space.py on lines 4013..4019
        myems-api/core/textmessage.py on lines 106..112
        myems-api/core/textmessage.py on lines 291..297
        myems-api/core/wechatmessage.py on lines 110..116
        myems-api/core/wechatmessage.py on lines 318..324

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 84.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                try:
                    upload = req.get_param('file')
                    # Read upload file as binary
                    attachment_file_object = upload.file.read()
                    # Retrieve filename
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 2 hrs to fix
        myems-api/core/emailmessage.py on lines 100..107

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 57.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                try:
                    upload = req.get_param('file')
                    # Read upload file as binary
                    attachment_file_object = upload.file.read()
                    # Retrieve filename
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 2 hrs to fix
        myems-api/core/emailmessage.py on lines 299..306

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 57.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                try:
                    raw_json = req.get_param('req')
                except Exception as ex:
                    raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', description=str(ex))
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 1 hr to fix
        myems-api/core/emailmessage.py on lines 309..312

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 43.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

                try:
                    raw_json = req.get_param('req')
                except Exception as ex:
                    raise falcon.HTTPError(status=falcon.HTTP_400, title='API.ERROR', description=str(ex))
        Severity: Major
        Found in myems-api/core/emailmessage.py and 1 other location - About 1 hr to fix
        myems-api/core/emailmessage.py on lines 109..112

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 43.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status