edgewall/trac

View on GitHub
trac/ticket/notification.py

Summary

Maintainability
F
5 days
Test Coverage

File notification.py has 628 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2005 Daniel Lundin <daniel@edgewall.com>
# Copyright (C) 2005-2006 Emmanuel Blot <emmanuel.blot@free.fr>
Severity: Major
Found in trac/ticket/notification.py - About 1 day to fix

    Function _format_plaintext has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
    Open

        def _format_plaintext(self, event):
            """Format ticket change notification e-mail (untranslated)"""
            ticket = event.target
            newticket = event.category == 'created'
            with translation_deactivated(ticket):
    Severity: Minor
    Found in trac/ticket/notification.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 _format_props has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        def _format_props(self, ticket):
            fields = [f for f in ticket.fields
                      if f['name'] not in ('summary', 'cc', 'time', 'changetime')]
            width = [0, 0, 0, 0]
            i = 0
    Severity: Minor
    Found in trac/ticket/notification.py - About 7 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 decorate_message has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        def decorate_message(self, event, message, charset):
            if event.realm != 'ticket':
                return
            from_email = self._get_from_email(event)
            if event.category == 'batchmodify':
    Severity: Minor
    Found in trac/ticket/notification.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 _ticket_change_subscribers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def _ticket_change_subscribers(subscriber, candidates):
        if not candidates:
            return
        if not isinstance(candidates, (list, set, tuple)):
            candidates = [candidates]
    Severity: Minor
    Found in trac/ticket/notification.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 matches has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def matches(self, event):
            cc_users = None
            if _is_ticket_change_event(event):
                # CC field is stored as comma-separated string. Parse to set.
                chrome = Chrome(self.env)
    Severity: Minor
    Found in trac/ticket/notification.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, category, target, time, author, comment=None,
    Severity: Major
    Found in trac/ticket/notification.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if field == 'description':
                                  new_descr = wrap(new, self.COLS, ' ', ' ', '\n',
                                                   self.ambiwidth)
                                  old_descr = wrap(old, self.COLS, '> ', '> ', '\n',
                                                   self.ambiwidth)
      Severity: Major
      Found in trac/ticket/notification.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if newv:
                                    change_data[field] = {'oldvalue': old,
                                                          'newvalue': new}
        
        
        Severity: Major
        Found in trac/ticket/notification.py - About 45 mins to fix

          Function __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self, targets, time, author, comment, new_values, action):
          Severity: Minor
          Found in trac/ticket/notification.py - About 45 mins to fix

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

                        if fname in ticket.time_fields:
                            format = ticket.fields.by_name(fname).get('format')
                            fval = self._format_time_field(fval, format)
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 415..417

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

                        if fname in ticket.time_fields:
                            format = ticket.fields.by_name(fname).get('format')
                            fval = self._format_time_field(fval, format)
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 379..381

            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

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

                                        if addcc:
                                            chgcc += wrap(" * cc: %s (added)" %
                                                          ', '.join(addcc),
                                                          self.COLS, ' ', ' ', '\n',
                                                          self.ambiwidth) + '\n'
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 189..193

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

            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 delcc:
                                            chgcc += wrap(" * cc: %s (removed)" %
                                                          ', '.join(delcc),
                                                          self.COLS, ' ', ' ', '\n',
                                                          self.ambiwidth) + '\n'
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 194..198

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

            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

                        ticket_values['description'] = wrap(
                            ticket_values.get('description', ''), self.COLS,
                            initial_indent=' ', subsequent_indent=' ', linesep='\n',
                            ambiwidth=self.ambiwidth)
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 232..235

            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

                        ticket_values['description'] = wrap(
                            ticket_values.get('description', ''), self.COLS,
                            initial_indent=' ', subsequent_indent=' ', linesep='\n',
                            ambiwidth=self.ambiwidth)
            Severity: Major
            Found in trac/ticket/notification.py and 1 other location - About 1 hr to fix
            trac/ticket/notification.py on lines 270..273

            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

                    added = [self._format_author(x)
                             for x in newcc if x and x not in oldcc]
            Severity: Minor
            Found in trac/ticket/notification.py and 1 other location - About 30 mins to fix
            trac/ticket/notification.py on lines 482..483

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

                    removed = [self._format_author(x)
                               for x in oldcc if x and x not in newcc]
            Severity: Minor
            Found in trac/ticket/notification.py and 1 other location - About 30 mins to fix
            trac/ticket/notification.py on lines 480..481

            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