django/django

View on GitHub
django/contrib/humanize/templatetags/humanize.py

Summary

Maintainability
F
5 days
Test Coverage

Function string_for has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def string_for(cls, value):
        if not isinstance(value, date):  # datetime is a subclass of date
            return value

        now = datetime.now(utc if is_aware(value) else None)
Severity: Minor
Found in django/contrib/humanize/templatetags/humanize.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 intcomma has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

def intcomma(value, use_l10n=True):
    """
    Convert an integer to a string containing commas every three digits.
    For example, 3000 becomes '3,000' and 45000 becomes '45,000'.
    """
Severity: Minor
Found in django/contrib/humanize/templatetags/humanize.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 intword has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def intword(value):
    """
    Convert a large integer to a friendly text representation. Works best
    for numbers over 1 million. For example, 1000000 becomes '1.0 million',
    1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'.
Severity: Minor
Found in django/contrib/humanize/templatetags/humanize.py - About 45 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 cls.time_strings['future-day'] % {
Severity: Major
Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                    return cls.time_strings['now']
    Severity: Major
    Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return cls.time_strings['future-hour'] % {'count': count}
      Severity: Major
      Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return cls.time_strings['past-minute'] % {'count': count}
        Severity: Major
        Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return cls.time_strings['past-hour'] % {'count': count}
          Severity: Major
          Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return cls.time_strings['future-second'] % {'count': delta.seconds}
            Severity: Major
            Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return cls.time_strings['future-minute'] % {'count': count}
              Severity: Major
              Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return defaultfilters.date(value, arg)
                Severity: Major
                Found in django/contrib/humanize/templatetags/humanize.py - About 30 mins to fix

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

                              if delta.days != 0:
                                  return cls.time_strings['future-day'] % {
                                      'delta': defaultfilters.timeuntil(value, now, time_strings=cls.future_substrings),
                                  }
                              elif delta.seconds == 0:
                  Severity: Major
                  Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
                  django/contrib/humanize/templatetags/humanize.py on lines 272..285

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

                  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 delta.days != 0:
                                  return cls.time_strings['past-day'] % {
                                      'delta': defaultfilters.timesince(value, now, time_strings=cls.past_substrings),
                                  }
                              elif delta.seconds == 0:
                  Severity: Major
                  Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 1 day to fix
                  django/contrib/humanize/templatetags/humanize.py on lines 288..301

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

                  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

                      future_substrings = {
                          # Translators: 'naturaltime-future' strings will be included in '%(delta)s from now'
                          'year': npgettext_lazy('naturaltime-future', '%d year', '%d years'),
                          'month': npgettext_lazy('naturaltime-future', '%d month', '%d months'),
                          'week': npgettext_lazy('naturaltime-future', '%d week', '%d weeks'),
                  Severity: Major
                  Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 2 hrs to fix
                  django/contrib/humanize/templatetags/humanize.py on lines 245..252

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

                  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

                      past_substrings = {
                          # Translators: 'naturaltime-past' strings will be included in '%(delta)s ago'
                          'year': npgettext_lazy('naturaltime-past', '%d year', '%d years'),
                          'month': npgettext_lazy('naturaltime-past', '%d month', '%d months'),
                          'week': npgettext_lazy('naturaltime-past', '%d week', '%d weeks'),
                  Severity: Major
                  Found in django/contrib/humanize/templatetags/humanize.py and 1 other location - About 2 hrs to fix
                  django/contrib/humanize/templatetags/humanize.py on lines 254..261

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

                  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