edgewall/trac

View on GitHub
trac/admin/console.py

Summary

Maintainability
F
3 days
Test Coverage

File console.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2023 Edgewall Software
# All rights reserved.
Severity: Minor
Found in trac/admin/console.py - About 6 hrs to fix

    Function do_initenv has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_initenv(self, line):
            def initenv_error(msg):
                printerr(_("Initenv for '%(env)s' failed.", env=self.envname),
                         "\n%s" % msg)
            if self.env_check():
    Severity: Minor
    Found in trac/admin/console.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 do_help has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_help(self, line=None):
            arg = self.arg_tokenize(line)
            if arg[0]:
                cmd_mgr = None
                doc = getattr(self, "_help_" + arg[0], None)
    Severity: Minor
    Found in trac/admin/console.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 _run has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def _run(args):
        if args is None:
            args = sys.argv[1:]
        admin = TracAdmin()
        if args:
    Severity: Minor
    Found in trac/admin/console.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

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

    class TracAdmin(cmd.Cmd):
        intro = ''
        doc_header = 'Trac Admin Console %(version)s\n' \
                     'Available Commands:\n' \
                     % {'version': TRAC_VERSION}
    Severity: Minor
    Found in trac/admin/console.py - About 2 hrs to fix

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

          def print_doc(cls, docs, stream=None, short=False, long=False):
              if stream is None:
                  stream = sys.stdout
              docs = [doc for doc in docs if doc[2]]
              if not docs:
      Severity: Minor
      Found in trac/admin/console.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 onecmd has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def onecmd(self, line):
              """`line` may be a `bytes` or a `str` object"""
              if isinstance(line, bytes):
                  if self.interactive:
                      encoding = sys.stdin.encoding
      Severity: Minor
      Found in trac/admin/console.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

      Avoid too many return statements within this function.
      Open

                  return 2
      Severity: Major
      Found in trac/admin/console.py - About 30 mins to fix

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

            def complete_line(self, text, line, cmd_only=False):
                args = self.arg_tokenize(line)
                if line and line[-1] == ' ':    # Space starts new argument
                    args.append('')
                comp = []
        Severity: Minor
        Found in trac/admin/console.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 default has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def default(self, line):
                try:
                    if not self.__env:
                        self._init_env()
                    if self.needs_upgrade is None:
        Severity: Minor
        Found in trac/admin/console.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 expand_macro has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def expand_macro(self, formatter, name, content, args=None):
                if content:
                    arg = content.strip().split()
                    doc = getattr(TracAdmin, "_help_" + arg[0], None)
                    if doc is None:
        Severity: Minor
        Found in trac/admin/console.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