um-cseg/chez-betty

View on GitHub
chezbetty/datalayer.py

Summary

Maintainability
F
1 wk
Test Coverage

File datalayer.py has 423 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools

from .models.model import *
from .models import event
from .models import transaction
Severity: Minor
Found in chezbetty/datalayer.py - About 6 hrs to fix

    Function undo_event has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

    def undo_event(e, user):
        assert(can_undo_event(e))
    
        line_items = {}
    
    
    Severity: Minor
    Found in chezbetty/datalayer.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 purchase has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    def purchase(user, account, items):
        assert(hasattr(user, "id"))
        assert(len(items) > 0)
    
        # Give discounts based on user type
    Severity: Minor
    Found in chezbetty/datalayer.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

    Consider simplifying this complex logical expression.
    Open

        if e.type != 'deposit' and e.type != 'purchase' and e.type != 'restock' \
           and e.type != 'inventory' and e.type != 'emptycashbox' \
           and e.type != 'emptysafe' \
           and e.type != 'donation' and e.type != 'withdrawal' \
           and e.type != 'reimbursement' \
    Severity: Critical
    Found in chezbetty/datalayer.py - About 2 hrs to fix

      Function deposit has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def deposit(user, account, amount, merge=True):
          assert(amount > 0.0)
          assert(hasattr(user, "id"))
      
          # Keep track of how much this deposit will be once merged (if needed)
      Severity: Minor
      Found in chezbetty/datalayer.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 restock has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def restock(items, global_cost, donation, reimbursee, admin, timestamp=None, old_event_id=None):
          e = event.Restock(admin, timestamp)
          DBSession.add(e)
          DBSession.flush()
          t = transaction.Restock(e, Decimal(global_cost), reimbursee)
      Severity: Minor
      Found in chezbetty/datalayer.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 restock has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def restock(items, global_cost, donation, reimbursee, admin, timestamp=None, old_event_id=None):
      Severity: Major
      Found in chezbetty/datalayer.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            for ss in s.subsubtransactions:
                                item = Item.from_id(ss.item_id)
                                item.in_stock -= ss.quantity
        
        
        Severity: Major
        Found in chezbetty/datalayer.py - About 45 mins to fix

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

          def bitcoin_deposit(user, amount, btc_transaction, address, amount_btc):
          Severity: Minor
          Found in chezbetty/datalayer.py - About 35 mins to fix

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

            def add_withdrawal(amount, notes, reimbursee, admin, timestamp=None):
            Severity: Minor
            Found in chezbetty/datalayer.py - About 35 mins to fix

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

              def cc_deposit(user, account, amount, txn_id, last4):
              Severity: Minor
              Found in chezbetty/datalayer.py - About 35 mins to fix

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

                def transfer_user_money(sender, recipient, amount, notes, admin):
                Severity: Minor
                Found in chezbetty/datalayer.py - About 35 mins to fix

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

                  def add_reimbursement(amount, notes, reimbursee, admin, timestamp=None):
                  Severity: Minor
                  Found in chezbetty/datalayer.py - About 35 mins to fix

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

                    def delete_item(item):
                        boxitems = DBSession.query(box_item.BoxItem).filter(box_item.BoxItem.item_id==item.id).all()
                        for bi in boxitems:
                            DBSession.delete(bi)
                        itemvendors = DBSession.query(item_vendor.ItemVendor).filter(item_vendor.ItemVendor.item_id==item.id).all()
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 7 hrs to fix
                    chezbetty/datalayer.py on lines 176..183

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

                    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 delete_box(box):
                        boxitems = DBSession.query(box_item.BoxItem).filter(box_item.BoxItem.box_id==box.id).all()
                        for bi in boxitems:
                            DBSession.delete(bi)
                        boxvendors = DBSession.query(box_vendor.BoxVendor).filter(box_vendor.BoxVendor.box_id==box.id).all()
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 7 hrs to fix
                    chezbetty/datalayer.py on lines 160..167

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

                    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 amount_missing != 0.0:
                            # Value of bitcoins fluctated and we didn't make as much as we expected
                    
                            if amount_missing > 0:
                                # We got less in bitcoins than we expected
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 4 hrs to fix
                    chezbetty/datalayer.py on lines 502..518

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

                    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 amount_missing != 0.0:
                            # If the amount in the safe doesn't match what we expected there to
                            # be, we need to adjust the amount in the cash box be transferring
                            # to or from a null account
                    
                    
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 4 hrs to fix
                    chezbetty/datalayer.py on lines 566..580

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

                    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 add_reimbursement(amount, notes, reimbursee, admin, timestamp=None):
                        e = event.Reimbursement(admin, notes, timestamp)
                        DBSession.add(e)
                        DBSession.flush()
                        t = transaction.Reimbursement(e, amount, reimbursee)
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 3 hrs to fix
                    chezbetty/datalayer.py on lines 616..622

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

                    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 add_withdrawal(amount, notes, reimbursee, admin, timestamp=None):
                        e = event.Withdrawal(admin, notes, timestamp)
                        DBSession.add(e)
                        DBSession.flush()
                        t = transaction.Withdrawal(e, amount, reimbursee)
                    Severity: Major
                    Found in chezbetty/datalayer.py and 1 other location - About 3 hrs to fix
                    chezbetty/datalayer.py on lines 626..632

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

                    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

                                        line_items[i] = '{},{},{},{},{},{},{}'.format(
                                            'item', s.item_id, s.quantity, s.wholesale,
                                            s.coupon_amount, s.sales_tax, s.bottle_deposit)
                    Severity: Minor
                    Found in chezbetty/datalayer.py and 1 other location - About 45 mins to fix
                    chezbetty/datalayer.py on lines 123..125

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

                    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

                                        line_items[i] = '{},{},{},{},{},{},{}'.format(
                                            'box', s.box_id, s.quantity, s.wholesale,
                                            s.coupon_amount, s.sales_tax, s.bottle_deposit)
                    Severity: Minor
                    Found in chezbetty/datalayer.py and 1 other location - About 45 mins to fix
                    chezbetty/datalayer.py on lines 118..120

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

                    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