edgewall/trac

View on GitHub
trac/versioncontrol/api.py

Summary

Maintainability
F
1 wk
Test Coverage

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

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2023 Edgewall Software
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
Severity: Major
Found in trac/versioncontrol/api.py - About 2 days to fix

    Function notify has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def notify(self, event, reponame, revs):
            """Notify repositories and change listeners about repository events.
    
            The supported events are the names of the methods defined in the
            `IRepositoryChangeListener` interface.
    Severity: Minor
    Found in trac/versioncontrol/api.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 get_resource_description has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_resource_description(self, resource, format=None, **kwargs):
            if resource.realm == self.changeset_realm:
                parent = resource.parent
                reponame = parent and parent.id
                id = resource.id
    Severity: Minor
    Found in trac/versioncontrol/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

    Repository has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Repository(object, metaclass=ABCMeta):
        """Base class for a repository provided by a version control system."""
    
        has_linear_changesets = False
    
    
    Severity: Minor
    Found in trac/versioncontrol/api.py - About 3 hrs to fix

      Function modify_repository has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def modify_repository(self, reponame, changes):
              """Modify attributes of a repository."""
              if is_default(reponame):
                  reponame = ''
              new_reponame = changes.get('name', reponame)
      Severity: Minor
      Found in trac/versioncontrol/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

      Function _get_connector has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_connector(self, rtype):
              """Retrieve the appropriate connector for the given repository type.
      
              Note that the self._lock must be held when calling this method.
              """
      Severity: Minor
      Found in trac/versioncontrol/api.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

      RepositoryManager has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class RepositoryManager(Component):
          """Version control system manager."""
      
          implements(IRequestFilter, IResourceManager, IRepositoryProvider,
                     ITemplateProvider)
      Severity: Minor
      Found in trac/versioncontrol/api.py - About 2 hrs to fix

        Function get_all_repositories has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_all_repositories(self):
                """Return a dictionary of repository information, indexed by name."""
                if not self._all_repositories:
                    all_repositories = {}
                    for provider in self.providers:
        Severity: Minor
        Found in trac/versioncontrol/api.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 pre_process_request has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def pre_process_request(self, req, handler):
                if handler is not Chrome(self.env):
                    for repo_info in self.get_all_repositories().values():
                        if not as_bool(repo_info.get('sync_per_request')):
                            continue
        Severity: Minor
        Found in trac/versioncontrol/api.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 get_repositories has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_repositories(self):
                """Retrieve repositories specified in TracIni.
        
                The `[repositories]` section can be used to specify a list
                of repositories.
        Severity: Minor
        Found in trac/versioncontrol/api.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 resource_exists has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def resource_exists(self, resource):
                if resource.realm == self.repository_realm:
                    reponame = resource.id
                else:
                    reponame = resource.parent.id
        Severity: Minor
        Found in trac/versioncontrol/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 get_repositories_by_dir has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_repositories_by_dir(self, directory):
                """Retrieve the repositories based on the given directory.
        
                   :param directory: the key for identifying the repositories.
                   :return: list of `Repository` instances.
        Severity: Minor
        Found in trac/versioncontrol/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

        Consider simplifying this complex logical expression.
        Open

                if resource.realm == self.changeset_realm:
                    parent = resource.parent
                    return href.changeset(resource.id, parent and parent.id or None)
                elif resource.realm == self.source_realm:
                    parent = resource.parent
        Severity: Major
        Found in trac/versioncontrol/api.py - About 1 hr to fix

          Function get_repositories has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_repositories(self):
                  """Retrieve repositories specified in the repository DB table."""
                  repos = {}
                  for id, name, value in self.env.db_query(
                          "SELECT id, name, value FROM repository WHERE name IN (%s)"
          Severity: Minor
          Found in trac/versioncontrol/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 'id' not in info:
                                      info['id'] = self.get_repository_id(reponame)
                                  all_repositories[reponame] = info
          Severity: Major
          Found in trac/versioncontrol/api.py - About 45 mins to fix

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

                def __init__(self, repos, rev, message=None, author=None, date=None):
            Severity: Minor
            Found in trac/versioncontrol/api.py - About 35 mins to fix

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

                  def get_changes(self, old_path, old_rev, new_path, new_rev,
              Severity: Minor
              Found in trac/versioncontrol/api.py - About 35 mins to fix

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

                    def __init__(self, repos, rev, message, author, date):
                Severity: Minor
                Found in trac/versioncontrol/api.py - About 35 mins to fix

                  Function get_repository has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_repository(self, reponame):
                          """Retrieve the appropriate `Repository` for the given
                          repository name.
                  
                          :param reponame: the key for specifying the repository.
                  Severity: Minor
                  Found in trac/versioncontrol/api.py - About 35 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 True
                  Severity: Major
                  Found in trac/versioncontrol/api.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return _("Repository %(repo)s", repo=resource.id)
                    Severity: Major
                    Found in trac/versioncontrol/api.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return False
                      Severity: Major
                      Found in trac/versioncontrol/api.py - About 30 mins to fix

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

                            def get_real_repositories(self):
                                """Return a sorted list of all real repositories (i.e. excluding
                                aliases).
                                """
                                repositories = set()
                        Severity: Minor
                        Found in trac/versioncontrol/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

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

                            def get_repository_by_path(self, path):
                                """Retrieve a matching `Repository` for the given `path`.
                        
                                :param path: the eventually scoped repository-scoped path
                                :return: a `(reponame, repos, path)` triple, where `path` is
                        Severity: Minor
                        Found in trac/versioncontrol/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

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

                            def get_resource_url(self, resource, href, **kwargs):
                                if resource.realm == self.changeset_realm:
                                    parent = resource.parent
                                    return href.changeset(resource.id, parent and parent.id or None)
                                elif resource.realm == self.source_realm:
                        Severity: Minor
                        Found in trac/versioncontrol/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

                        There are no issues that match your filters.

                        Category
                        Status