edgewall/trac

View on GitHub
trac/ticket/api.py

Summary

Maintainability
F
4 days
Test Coverage

File api.py has 605 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# Copyright (C) 2003-2005 Jonas Borgström <jonas@edgewall.com>
# All rights reserved.
Severity: Major
Found in trac/ticket/api.py - About 1 day to fix

    Function _format_comment_link has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        def _format_comment_link(self, formatter, ns, target, label):
            resource = None
            if ':' in target:
                elts = target.split(':')
                if len(elts) == 3:
    Severity: Minor
    Found in trac/ticket/api.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 validate_ticket has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_ticket(self, req, ticket):
            # Validate select fields for known values.
            for field in ticket.fields:
                if 'options' not in field:
                    continue
    Severity: Minor
    Found in trac/ticket/api.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 custom_fields has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def custom_fields(self):
            """Return the list of custom ticket fields available for tickets."""
            fields = TicketFieldList()
            config = self.ticket_custom_section
            for name in [option for option, value in config.options()
    Severity: Minor
    Found in trac/ticket/api.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

    TicketSystem has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TicketSystem(Component):
        implements(IPermissionRequestor, IWikiSyntaxProvider, IResourceManager,
                   ITicketManipulator)
    
        change_listeners = ExtensionPoint(ITicketChangeListener)
    Severity: Minor
    Found in trac/ticket/api.py - About 2 hrs to fix

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

          def _format_link(self, formatter, ns, target, label, fullmatch=None):
              intertrac = formatter.shorthand_intertrac_helper(ns, target, label,
                                                               fullmatch)
              if intertrac:
                  return intertrac
      Severity: Minor
      Found in trac/ticket/api.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 fields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def fields(self):
              """Return the list of fields available for tickets."""
              from trac.ticket import model
      
              fields = TicketFieldList()
      Severity: Minor
      Found in trac/ticket/api.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 get_available_actions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_available_actions(self, req, ticket):
              """Returns a sorted list of available actions"""
              # The list should not have duplicates.
              actions = {}
              for controller in self.action_controllers:
      Severity: Minor
      Found in trac/ticket/api.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 deeply nested control flow statements.
      Open

                              if cnum == 'description':
                                  title = _("Description for #%(id)s: %(summary)s",
                                            id=resource.id, summary=summary)
                              else:
                                  title = _("Comment %(cnum)s for #%(id)s: "
      Severity: Major
      Found in trac/ticket/api.py - About 45 mins to fix

        Consider simplifying this complex logical expression.
        Open

                if resource and resource.id and resource.realm == self.realm and \
                        cnum and (cnum.isdigit() or cnum == 'description'):
                    href = title = class_ = None
                    if self.resource_exists(resource):
                        from trac.ticket.model import Ticket
        Severity: Major
        Found in trac/ticket/api.py - About 40 mins to fix

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

              def _format_link(self, formatter, ns, target, label, fullmatch=None):
          Severity: Minor
          Found in trac/ticket/api.py - About 35 mins to fix

            Function get_allowed_owners has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def get_allowed_owners(self, ticket=None):
                    """Returns a list of permitted ticket owners (those possessing the
                    TICKET_MODIFY permission). Returns `None` if the option `[ticket]`
                    `restrict_owner` is `False`.
            
            
            Severity: Minor
            Found in trac/ticket/api.py - About 25 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

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

                    if not ticket['summary']:
                        yield 'summary', _("Tickets must contain a summary.")
                    elif len(ticket['summary'] or '') > self.max_summary_size:
                        yield 'summary', _("Must be less than or equal to %(num)s "
                                           "characters", num=self.max_summary_size)
            Severity: Major
            Found in trac/ticket/api.py and 1 other location - About 1 hr to fix
            trac/ticket/api.py on lines 539..542

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

            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 len(ticket['description'] or '') > self.max_description_size:
                        yield 'description', _("Must be less than or equal to %(num)s "
                                               "characters",
                                               num=self.max_description_size)
            Severity: Major
            Found in trac/ticket/api.py and 1 other location - About 1 hr to fix
            trac/ticket/api.py on lines 545..549

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

            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

                    fields.sort(key=lambda f: (f['order'], f['name']))
            Severity: Minor
            Found in trac/ticket/api.py and 1 other location - About 30 mins to fix
            trac/notification/api.py on lines 189..190

            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