edgewall/trac

View on GitHub
trac/ticket/query.py

Summary

Maintainability
F
2 wks
Test Coverage

Function get_sql has a Cognitive Complexity of 191 (exceeds 5 allowed). Consider refactoring.
Open

    def get_sql(self, req=None, cached_ids=None, authname=None):
        """Return a (sql, params) tuple for the query.
        """
        if req is not None:
            authname = req.authname
Severity: Minor
Found in trac/ticket/query.py - About 3 days 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

File query.py has 1284 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2004-2023 Edgewall Software
# Copyright (C) 2004-2005 Christopher Lenz <cmlenz@gmx.de>
# Copyright (C) 2005-2007 Christian Boos <cboos@edgewall.org>
Severity: Major
Found in trac/ticket/query.py - About 3 days to fix

    Function _get_constraints has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_constraints(self, req=None, arg_list=[]):
            fields = TicketSystem(self.env).get_ticket_fields()
            synonyms = TicketSystem(self.env).get_field_synonyms()
            fields = {f['name']: f for f in fields}
            fields['id'] = {'type': 'id'}
    Severity: Minor
    Found in trac/ticket/query.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 template_data has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
    Open

        def template_data(self, context, tickets, orig_list=None, orig_time=None,
                          req=None):
            clauses = []
            for clause in self.constraints:
                constraints = {}
    Severity: Minor
    Found in trac/ticket/query.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 process_request has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        def process_request(self, req):
            req.perm(self.realm).require('TICKET_VIEW')
            report_id = req.args.as_int('report')
            if report_id:
                req.perm('report', report_id).require('REPORT_VIEW')
    Severity: Minor
    Found in trac/ticket/query.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 expand_macro has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        def expand_macro(self, formatter, name, content):
            req = formatter.req
            query_string, kwargs, format = self.parse_args(content)
            if query_string:
                query_string += '&'
    Severity: Minor
    Found in trac/ticket/query.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 _export_csv has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        def _export_csv(self, req, query, sep=',', mimetype='text/plain'):
            def iterate():
                out = io.BytesIO()
                writer = csv.writer(io.TextIOWrapper(out, encoding='utf-8',
                                                     newline='\n',
    Severity: Minor
    Found in trac/ticket/query.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 execute has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def execute(self, req=None, cached_ids=None, authname=None, href=None):
            """Retrieve the list of matching tickets.
            """
            if req is not None:
                href = req.href
    Severity: Minor
    Found in trac/ticket/query.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 __init__ has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, env, report=None, constraints=None, cols=None,
                     order=None, desc=0, group=None, groupdesc=0, verbose=0,
                     rows=None, page=None, max=None, format=None):
            self.env = env
            self.id = report  # if not None, it's the corresponding saved query
    Severity: Minor
    Found in trac/ticket/query.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_default_columns has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_default_columns(self):
            cols = self.get_all_columns()
    
            # Semi-intelligently remove columns that are restricted to a single
            # value by a query constraint.
    Severity: Minor
    Found in trac/ticket/query.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 from_string has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_string(cls, env, string, **kw):
            kw_strs = ['order', 'group', 'page', 'max', 'format']
            kw_arys = ['rows']
            kw_bools = ['desc', 'groupdesc', 'verbose']
            kw_synonyms = {'row': 'rows'}
    Severity: Minor
    Found in trac/ticket/query.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 parse_args has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_args(content):
            """Parse macro arguments and translate them to a query string."""
            clauses = [{}]
            argv = []
            kwargs = {}
    Severity: Minor
    Found in trac/ticket/query.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_href has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_href(self, href, id=None, order=None, desc=None, format=None,
                     max=None, page=None):
            """Create a link corresponding to this query.
    
            :param href: the `Href` object used to build the URL
    Severity: Minor
    Found in trac/ticket/query.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 __init__ has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, env, report=None, constraints=None, cols=None,
    Severity: Major
    Found in trac/ticket/query.py - About 1 hr to fix

      Function display_html has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def display_html(self, req, query):
              # The most recent query is stored in the user session;
              orig_list = None
              orig_time = datetime_now(utc)
              query_time = req.session.as_int('query_time', 0)
      Severity: Minor
      Found in trac/ticket/query.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 __init__ has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self, env, report=None, constraints=None, cols=None,
                       order=None, desc=0, group=None, groupdesc=0, verbose=0,
                       rows=None, page=None, max=None, format=None):
              self.env = env
              self.id = report  # if not None, it's the corresponding saved query
      Severity: Minor
      Found in trac/ticket/query.py - About 1 hr to fix

        Function display_html has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def display_html(self, req, query):
                # The most recent query is stored in the user session;
                orig_list = None
                orig_time = datetime_now(utc)
                query_time = req.session.as_int('query_time', 0)
        Severity: Minor
        Found in trac/ticket/query.py - About 1 hr to fix

          Function get_all_columns has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_all_columns(self):
                  # Prepare the default list of columns
                  cols = ['id']
                  cols += [f['name'] for f in self.fields if f['type'] != 'textarea']
                  for col in ('reporter', 'keywords', 'cc'):
          Severity: Minor
          Found in trac/ticket/query.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_href has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def get_href(self, href, id=None, order=None, desc=None, format=None,
          Severity: Major
          Found in trac/ticket/query.py - About 50 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if 0 <= idx < len(vals):
                                        del vals[idx]
                                        if not vals:
                                            continue
                                    else:
            Severity: Major
            Found in trac/ticket/query.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if ends:
                                          vals = [start + '..' + end
                                                  for (start, end) in zip(vals, ends)]
                                  if k in remove_constraints:
              Severity: Major
              Found in trac/ticket/query.py - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if not word:
                                                continue
                                        clauses.append("COALESCE(%s,'') %s%s" % (col, cneg,
                Severity: Major
                Found in trac/ticket/query.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if user:
                                              vals[i] = val.replace('$USER', user)
                                          elif val.endswith('$USER'):
                                              del clause[field]
                                              break
                  Severity: Major
                  Found in trac/ticket/query.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                if a == b:
                                                    ids.append(str(a))
                                                else:
                                                    id_clauses.append('t.id BETWEEN %s AND %s')
                                                    args.append(a)
                    Severity: Major
                    Found in trac/ticket/query.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if href is not None:
                                                  result['href'] = href.ticket(val)
                                          elif name in self.time_fields:
                      Severity: Major
                      Found in trac/ticket/query.py - About 45 mins to fix

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

                            def template_data(self, context, tickets, orig_list=None, orig_time=None,
                        Severity: Minor
                        Found in trac/ticket/query.py - About 35 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return tag.span(_("No results"), class_='query_no_results')
                          Severity: Major
                          Found in trac/ticket/query.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                                return (('NOT ' if neg else '')
                            Severity: Major
                            Found in trac/ticket/query.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return tag.span(alist[0], *[(', ', a) for a in alist[1:]])
                              Severity: Major
                              Found in trac/ticket/query.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                return tag.div(tag.dl([(tag.dt(ticket_anchor(ticket)),
                                Severity: Major
                                Found in trac/ticket/query.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                  return ("COALESCE(%s,'') %s%s" % (col, 'NOT ' if neg else '',
                                  Severity: Major
                                  Found in trac/ticket/query.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return tag.div(
                                    Severity: Major
                                    Found in trac/ticket/query.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                      return tag(groups[0], [(', ', g) for g in groups[1:]])
                                      Severity: Major
                                      Found in trac/ticket/query.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                            return ("COALESCE(%s,'')%s=%%s"
                                        Severity: Major
                                        Found in trac/ticket/query.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                              return None
                                          Severity: Major
                                          Found in trac/ticket/query.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                            return tag.div(
                                            Severity: Major
                                            Found in trac/ticket/query.py - About 30 mins to fix

                                              There are no issues that match your filters.

                                              Category
                                              Status