webservices/utils.py

Summary

Maintainability
D
1 day
Test Coverage

File utils.py has 327 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re
import functools
import json
import logging

Severity: Minor
Found in webservices/utils.py - About 3 hrs to fix

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

        def _fetch(self, last_index, sort_index=None, limit=None, eager=True):
            cursor = self.cursor
            direction = self.sort_column[1] if self.sort_column else sa.asc
            lhs, rhs = (), ()
    
    
    Severity: Minor
    Found in webservices/utils.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 fetch_page has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def fetch_page(query, kwargs, model=None, aliases=None, join_columns=None, clear=False,
    Severity: Major
    Found in webservices/utils.py - About 1 hr to fix

      Function fetch_seek_page has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def fetch_seek_page(query, kwargs, index_column, clear=False, count=None, cap=100, eager=True):
      Severity: Major
      Found in webservices/utils.py - About 50 mins to fix

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

        def related(related_model, id_label, related_id_label=None, cycle_label=None,
        Severity: Minor
        Found in webservices/utils.py - About 45 mins to fix

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

          def fetch_seek_paginator(query, kwargs, index_column, clear=False, count=None, cap=100):
          Severity: Minor
          Found in webservices/utils.py - About 45 mins to fix

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

                def __init__(self, cursor, per_page, index_column, sort_column=None, count=None):
            Severity: Minor
            Found in webservices/utils.py - About 35 mins to fix

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

              def document_description(report_year, report_type=None, document_type=None, form_type=None):
                  if report_type:
                      clean = re.sub(r'\{[^)]*\}', '', report_type)
                  elif document_type:
                      clean = document_type
              Severity: Minor
              Found in webservices/utils.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

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

              def related(related_model, id_label, related_id_label=None, cycle_label=None,
                          related_cycle_label=None, use_modulus=True):
                  from webservices.common.models import db
                  related_model = get_model(related_model)
                  related_id_label = related_id_label or id_label
              Severity: Minor
              Found in webservices/utils.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 check_election_arguments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def check_election_arguments(kwargs):
                  for arg in office_args_required:
                      if kwargs.get(arg) is None:
                          raise exceptions.ApiError(
                              'Required parameter "{0}" not found.'.format(arg),
              Severity: Minor
              Found in webservices/utils.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_index_values has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _get_index_values(self, result):
                      """Get index values from last result, to be used in seeking to the next
                      page. Optionally include sort values, if any.
                      """
                      ret = {
              Severity: Minor
              Found in webservices/utils.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 fetch_seek_page has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def fetch_seek_page(query, kwargs, index_column, clear=False, count=None, cap=100, eager=True):
                  paginator = fetch_seek_paginator(query, kwargs, index_column, clear=clear, count=count, cap=cap)
                  if paginator.sort_column is not None:
                      sort_index = kwargs['last_{0}'.format(paginator.sort_column[2])]
                      null_sort_by = paginator.sort_column[0]
              Severity: Minor
              Found in webservices/utils.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 sort and multi:
                      query, _ = sorting.multi_sort(
                          query, sort, model=model, aliases=aliases, join_columns=join_columns,
              Severity: Minor
              Found in webservices/utils.py and 1 other location - About 40 mins to fix
              webservices/utils.py on lines 75..77

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

              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

                  elif sort:
                      query, _ = sorting.sort(
                          query, sort, model=model, aliases=aliases, join_columns=join_columns,
              Severity: Minor
              Found in webservices/utils.py and 1 other location - About 40 mins to fix
              webservices/utils.py on lines 70..72

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

              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