um-cseg/chez-betty

View on GitHub
chezbetty/models/user.py

Summary

Maintainability
F
4 days
Test Coverage

Function iterate_recent_items has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    def iterate_recent_items(self, limit=None, allow_duplicates=False, pictures_only=True):
        cap_search = 20
        items = set()
        count = 0
        for e in self.events:
Severity: Minor
Found in chezbetty/models/user.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

User has 32 functions (exceeds 20 allowed). Consider refactoring.
Open

class User(account.Account):
    __tablename__ = 'users'
    __mapper_args__ = {'polymorphic_identity': 'user'}

    id        = Column(Integer, ForeignKey("accounts.id"), primary_key=True)
Severity: Minor
Found in chezbetty/models/user.py - About 4 hrs to fix

    File user.py has 326 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from pyramid.security import authenticated_userid
    import hashlib
    import binascii
    import os
    from .model import *
    Severity: Minor
    Found in chezbetty/models/user.py - About 3 hrs to fix

      Avoid deeply nested control flow statements.
      Open

                              for line_item in transaction.subtransactions:
                                  cap_search -= 1
                                  if cap_search == 0:
                                      return
                                  if (line_item.item not in items) or allow_duplicates:
      Severity: Major
      Found in chezbetty/models/user.py - About 45 mins to fix

        Avoid too many return statements within this function.
        Open

                return ["serviceaccount"]
        Severity: Major
        Found in chezbetty/models/user.py - About 30 mins to fix

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

              @classmethod
              def get_amount_held(cls):
                  return DBSession.query(func.sum(User.balance).label("total_balance"))\
                                  .filter(User.balance>0)\
                                  .one().total_balance or Decimal(0.0)
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/pool.py on lines 83..87

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

          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

              @classmethod
              def get_amount_owed(cls):
                  return DBSession.query(func.sum(User.balance).label("total_balance"))\
                                  .filter(User.balance<0)\
                                  .one().total_balance or Decimal(0.0)
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/pool.py on lines 89..93

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

          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

              @classmethod
              def get_normal_users(cls):
                  return DBSession.query(cls)\
                                  .filter(cls.enabled)\
                                  .filter(cls.archived == False)\
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/user.py on lines 221..226

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

          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

              @classmethod
              def get_archived_users(cls):
                  return DBSession.query(cls)\
                                  .filter(cls.enabled)\
                                  .filter(cls.archived == True)\
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/user.py on lines 214..219

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

          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 purchase_threshold_check(self, limit=None):
                  count = 0
                  for e in self.events:
                      if e.type == 'purchase':
                          count += 1
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/user.py on lines 307..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 50.

          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 deposit_threshold_check(self, limit=None):
                  count = 0
                  for e in self.events:
                      if e.type == 'deposit':
                          count += 1
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 2 hrs to fix
          chezbetty/models/user.py on lines 300..305

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

          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

              @classmethod
              def get_users_total(cls):
                  return DBSession.query(func.sum(User.balance).label("total_balance"))\
                                  .one().total_balance or Decimal(0.0)
          Severity: Major
          Found in chezbetty/models/user.py and 1 other location - About 1 hr to fix
          chezbetty/models/reimbursee.py on lines 53..56

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

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

              @classmethod
              def get_disabled_users(cls):
                  return DBSession.query(cls)\
                                  .filter(cls.enabled == False)\
                                  .order_by(cls.name).all()
          Severity: Major
          Found in chezbetty/models/user.py and 8 other locations - About 1 hr to fix
          chezbetty/models/box.py on lines 65..69
          chezbetty/models/ephemeron.py on lines 21..25
          chezbetty/models/item.py on lines 84..88
          chezbetty/models/pool.py on lines 39..43
          chezbetty/models/pool.py on lines 46..50
          chezbetty/models/reimbursee.py on lines 32..36
          chezbetty/models/tag.py on lines 22..26
          chezbetty/models/vendor.py on lines 26..30

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

              @classmethod
              def all(cls):
                  return DBSession.query(cls)\
                                  .filter(cls.enabled)\
                                  .order_by(cls.name)\
          Severity: Major
          Found in chezbetty/models/user.py and 4 other locations - About 55 mins to fix
          chezbetty/models/box.py on lines 50..54
          chezbetty/models/item.py on lines 78..82
          chezbetty/models/reimbursee.py on lines 25..29
          chezbetty/models/vendor.py on lines 20..24

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

          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 lookup_uniqname(self, uniqname, details=False):
                  if details:
                      return self.__detail_lookup("uid", uniqname)
                  else:
                      return self.__lookup("uid", uniqname)
          Severity: Minor
          Found in chezbetty/models/user.py and 1 other location - About 45 mins to fix
          chezbetty/models/user.py on lines 96..100

          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

              def lookup_umid(self, umid, details=False):
                  if details:
                      return self.__detail_lookup("entityid", umid)
                  else:
                      return self.__lookup("entityid", umid)
          Severity: Minor
          Found in chezbetty/models/user.py and 1 other location - About 45 mins to fix
          chezbetty/models/user.py on lines 102..106

          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