um-cseg/chez-betty

View on GitHub
chezbetty/utility.py

Summary

Maintainability
F
3 days
Test Coverage

Function _send_email has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

def _send_email(msg, FROM):
    settings = get_current_registry().settings

    if suppress_emails():
        print("Mail suppressed due to debug settings")
Severity: Minor
Found in chezbetty/utility.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

File utility.py has 303 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from decimal import Decimal
import itertools
import qrcode
import qrcode.image.svg
import stripe
Severity: Minor
Found in chezbetty/utility.py - About 3 hrs to fix

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

    def group(rows, period='day'):
    
        def fix_timezone(i):
            return i.timestamp.to('America/Detroit')
        def group_month(i):
    Severity: Minor
    Found in chezbetty/utility.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 timeseries_balance_total_daily has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def timeseries_balance_total_daily(rows):
    
        # Is debt going away or coming in
        directions = {
            'purchase':   -1, # user balance goes down by amount
    Severity: Minor
    Found in chezbetty/utility.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 post_stripe_payment has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def post_stripe_payment(
    Severity: Major
    Found in chezbetty/utility.py - About 1 hr to fix

      Function send_bcc_email has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def send_bcc_email(BCC, SUBJECT, body,
      Severity: Minor
      Found in chezbetty/utility.py - About 35 mins to fix

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

        def send_email(TO, SUBJECT, body,
        Severity: Minor
        Found in chezbetty/utility.py - About 35 mins to fix

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

          def get_days_on_shame(user, rows):
              directions = {
                  'purchase':   -1, # user balance goes down by amount
                  'cashdeposit': 1, # user balance goes up by amount
                  'ccdeposit':   1,
          Severity: Minor
          Found in chezbetty/utility.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 True
          Severity: Major
          Found in chezbetty/utility.py - About 30 mins to fix

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

            def send_email(TO, SUBJECT, body,
                    FROM='chez-betty@umich.edu',
                    encoding='html',
                    ):
                msg = MIMEMultipart()
            Severity: Major
            Found in chezbetty/utility.py and 1 other location - About 6 hrs to fix
            chezbetty/utility.py on lines 95..108

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

            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

            def send_bcc_email(BCC, SUBJECT, body,
                    FROM='chez-betty@umich.edu',
                    encoding='html',
                    ):
                msg = MIMEMultipart()
            Severity: Major
            Found in chezbetty/utility.py and 1 other location - About 6 hrs to fix
            chezbetty/utility.py on lines 79..92

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

            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 3 locations. Consider refactoring.
            Open

                        try:
                            msg.replace_header('BCC', settings['debugging_send_email_to'])
                            print("DEBUG: e-mail BCC overidden to {}".format(msg['BCC']))
                        except KeyError: pass
            Severity: Major
            Found in chezbetty/utility.py and 2 other locations - About 1 hr to fix
            chezbetty/utility.py on lines 59..62
            chezbetty/utility.py on lines 63..66

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

            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 3 locations. Consider refactoring.
            Open

                        try:
                            msg.replace_header('To', settings['debugging_send_email_to'])
                            print("DEBUG: e-mail TO overidden to {}".format(msg['To']))
                        except KeyError: pass
            Severity: Major
            Found in chezbetty/utility.py and 2 other locations - About 1 hr to fix
            chezbetty/utility.py on lines 63..66
            chezbetty/utility.py on lines 67..70

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

            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 3 locations. Consider refactoring.
            Open

                        try:
                            msg.replace_header('CC', settings['debugging_send_email_to'])
                            print("DEBUG: e-mail CC overidden to {}".format(msg['CC']))
                        except KeyError: pass
            Severity: Major
            Found in chezbetty/utility.py and 2 other locations - About 1 hr to fix
            chezbetty/utility.py on lines 59..62
            chezbetty/utility.py on lines 67..70

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

            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 3 locations. Consider refactoring.
            Open

            def new_user_email(user):
                send_email(
                        TO=user.uniqname+'@umich.edu',
                        SUBJECT='[Chez Betty] Welcome to Chez Betty!',
                        body=render('templates/admin/email_new_user.jinja2',
            Severity: Minor
            Found in chezbetty/utility.py and 2 other locations - About 30 mins to fix
            chezbetty/utility.py on lines 124..128
            chezbetty/views_terminal.py on lines 374..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 32.

            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 3 locations. Consider refactoring.
            Open

                send_email(
                        TO=user.uniqname+'@umich.edu',
                        SUBJECT='[Chez Betty] You are on top of the Wall of Shame! :(',
                        body=render('templates/admin/email_new_top_wall_of_shame.jinja2',
                            {'user': user})
            Severity: Minor
            Found in chezbetty/utility.py and 2 other locations - About 30 mins to fix
            chezbetty/utility.py on lines 140..145
            chezbetty/views_terminal.py on lines 374..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 32.

            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