myems-api/core/webmessage.py

Summary

Maintainability
F
2 wks
Test Coverage

File webmessage.py has 667 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: Major
Found in myems-api/core/webmessage.py - About 1 day to fix

    Function on_get has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_get(req, resp):
            access_control(req)
            start_datetime_local = req.params.get('startdatetime')
            end_datetime_local = req.params.get('enddatetime')
            status = req.params.get('status')
    Severity: Minor
    Found in myems-api/core/webmessage.py - About 1 day 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 42 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_get(req, resp):
            """Handles GET requests"""
            access_control(req)
            # Verify User Session
            token = req.headers.get('TOKEN')
    Severity: Minor
    Found in myems-api/core/webmessage.py - About 6 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 a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_put(req, resp, id_):
            """Handles PUT requests"""
            access_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/webmessage.py - About 5 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 a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_put(req, resp):
            """Handles PUT requests"""
            access_control(req)
            try:
                raw_json = req.stream.read().decode('utf-8')
    Severity: Minor
    Found in myems-api/core/webmessage.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_get has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

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

        def on_delete(req, resp, id_):
            access_control(req)
            if not id_.isdigit() or int(id_) <= 0:
                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                       description='API.INVALID_WEB_MESSAGE_ID')
    Severity: Minor
    Found in myems-api/core/webmessage.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_get has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def on_get(req, resp):
            access_control(req)
            start_datetime_local = req.params.get('startdatetime')
            end_datetime_local = req.params.get('enddatetime')
            status = req.params.get('status')
    Severity: Minor
    Found in myems-api/core/webmessage.py - About 1 hr to fix

      Function on_put has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def on_put(req, resp, id_):
              """Handles PUT requests"""
              access_control(req)
              try:
                  raw_json = req.stream.read().decode('utf-8')
      Severity: Minor
      Found in myems-api/core/webmessage.py - About 1 hr to fix

        Function on_put has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def on_put(req, resp):
                """Handles PUT requests"""
                access_control(req)
                try:
                    raw_json = req.stream.read().decode('utf-8')
        Severity: Minor
        Found in myems-api/core/webmessage.py - About 1 hr to fix

          Function on_get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def on_get(req, resp, id_):
                  """Handles GET requests"""
                  access_control(req)
                  if not id_.isdigit() or int(id_) <= 0:
                      raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
          Severity: Minor
          Found in myems-api/core/webmessage.py - About 1 hr to fix

            Function on_delete has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def on_delete(req, resp, id_):
                    access_control(req)
                    if not id_.isdigit() or int(id_) <= 0:
                        raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                               description='API.INVALID_WEB_MESSAGE_ID')
            Severity: Minor
            Found in myems-api/core/webmessage.py - About 1 hr to fix

              Function on_get has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def on_get(req, resp):
                      """Handles GET requests"""
                      access_control(req)
                      # Verify User Session
                      token = req.headers.get('TOKEN')
              Severity: Minor
              Found in myems-api/core/webmessage.py - About 1 hr to fix

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

                        if rows is not None and len(rows) > 0:
                            for row in rows:
                                meta_result = {"id": row[0],
                                               "subject": row[1],
                                               "message": row[2].replace("<br>", ""),
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 2 days to fix
                myems-api/core/webmessage.py on lines 271..282

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

                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

                        if rows is not None and len(rows) > 0:
                            for row in rows:
                                meta_result = {"id": row[0],
                                               "subject": row[1],
                                               "message": row[2].replace("<br>", ""),
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 2 days to fix
                myems-api/core/webmessage.py on lines 167..178

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

                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

                        if status == 'acknowledged':
                            if 'reply' not in new_values['data'].keys() or \
                                not isinstance(new_values['data']['reply'], str) or \
                                    len(str.strip(new_values['data']['reply'])) == 0:
                                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_REPLY')
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 1 day to fix
                myems-api/core/webmessage.py on lines 309..317

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

                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

                        if status == 'acknowledged':
                            if 'reply' not in new_values['data'].keys() or \
                                    not isinstance(new_values['data']['reply'], str) or \
                                    len(str.strip(new_values['data']['reply'])) == 0:
                                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_REPLY')
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 1 day to fix
                myems-api/core/webmessage.py on lines 535..543

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

                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', 'read'):
                            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                Severity: Major
                Found in myems-api/core/webmessage.py and 6 other locations - About 1 day to fix
                myems-api/core/emailmessage.py on lines 356..360
                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 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 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', 'read'):
                            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                Severity: Major
                Found in myems-api/core/webmessage.py and 6 other locations - About 1 day to fix
                myems-api/core/emailmessage.py on lines 356..360
                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/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

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

                        if ids is None or rt is None:
                            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 1 hr to fix
                myems-api/core/webmessage.py on lines 739..740

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

                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

                        if ids is None or rt is None:
                            raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                Severity: Major
                Found in myems-api/core/webmessage.py and 1 other location - About 1 hr to fix
                myems-api/core/webmessage.py on lines 769..770

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

                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

                            if priority not in ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL', 'ALL']:
                                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                                       description='API.INVALID_PRIORITY')
                            else:
                                if priority == 'ALL':
                Severity: Minor
                Found in myems-api/core/webmessage.py and 1 other location - About 35 mins to fix
                myems-api/core/webmessage.py on lines 67..74

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

                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

                            if status not in ['new', 'read', 'acknowledged', 'all']:
                                raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST',
                                                       description='API.INVALID_STATUS')
                            else:
                                if status == 'all':
                Severity: Minor
                Found in myems-api/core/webmessage.py and 1 other location - About 35 mins to fix
                myems-api/core/webmessage.py on lines 81..88

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

                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