webservices/resources/legal.py

Summary

Maintainability
F
3 days
Test Coverage

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

def apply_ao_specific_query_params(query, **kwargs):
    must_clauses = []
    if kwargs.get('ao_no'):
        must_clauses.append(Q('terms', no=kwargs.get('ao_no')))

Severity: Minor
Found in webservices/resources/legal.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

File legal.py has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re

from elasticsearch_dsl import Search, Q
from webargs import fields
from flask import abort
Severity: Minor
Found in webservices/resources/legal.py - About 2 hrs to fix

    Function execute_query has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def execute_query(query):
        es_results = query.execute()
        formatted_hits = []
        for hit in es_results:
            formatted_hit = hit.to_dict()
    Severity: Minor
    Found in webservices/resources/legal.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 apply_mur_specific_query_params has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def apply_mur_specific_query_params(query, **kwargs):
        must_clauses = []
        if kwargs.get('mur_no'):
            must_clauses.append(Q('terms', no=kwargs.get('mur_no')))
        if kwargs.get('mur_respondents'):
    Severity: Minor
    Found in webservices/resources/legal.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 generic_query_builder has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def generic_query_builder(q, type_, from_hit, hits_returned, **kwargs):
    Severity: Minor
    Found in webservices/resources/legal.py - About 35 mins to fix

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

      def mur_query_builder(q, type_, from_hit, hits_returned, **kwargs):
      Severity: Minor
      Found in webservices/resources/legal.py - About 35 mins to fix

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

        def ao_query_builder(q, type_, from_hit, hits_returned, **kwargs):
        Severity: Minor
        Found in webservices/resources/legal.py - About 35 mins to fix

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

              query = Search().using(es) \
                  .query(Q('bool', must=must_query)) \
                  .highlight('text', 'name', 'no', 'summary', 'documents.text', 'documents.description') \
                  .highlight_options(require_field_match=False) \
                  .source(exclude=['text', 'documents.text', 'sort1', 'sort2']) \
          Severity: Major
          Found in webservices/resources/legal.py and 1 other location - About 4 hrs to fix
          webservices/resources/legal.py on lines 127..134

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

          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

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

              query = Search().using(es) \
                  .query(Q('bool', must=must_query)) \
                  .highlight('text', 'name', 'no', 'summary', 'documents.text', 'documents.description') \
                  .highlight_options(require_field_match=False) \
                  .source(exclude=['text', 'documents.text', 'sort1', 'sort2']) \
          Severity: Major
          Found in webservices/resources/legal.py and 1 other location - About 4 hrs to fix
          webservices/resources/legal.py on lines 110..117

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

          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

              @property
              def args(self):
                  return {"citation_type": fields.Str(required=True, description="Citation type (regulation or statute)"),
                  "citation": fields.Str(required=True, description='Citation to search for.')}
          Severity: Major
          Found in webservices/resources/legal.py and 1 other location - About 1 hr to fix
          webservices/resources/legal.py on lines 53..56

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

          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

              @property
              def args(self):
                  return {"no": fields.Str(required=True, description='Document number to fetch.'),
                          "doc_type": fields.Str(required=True, description='Document type to fetch.')}
          Severity: Major
          Found in webservices/resources/legal.py and 1 other location - About 1 hr to fix
          webservices/resources/legal.py on lines 31..34

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('mur_respondents'):
                  must_clauses.append(Q('match', respondents=kwargs.get('mur_respondents')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 223..224
          webservices/resources/legal.py on lines 226..227

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('mur_election_cycles'):
                  must_clauses.append(Q('term', election_cycles=kwargs.get('mur_election_cycles')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 223..224
          webservices/resources/legal.py on lines 226..227

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('ao_no'):
                  must_clauses.append(Q('terms', no=kwargs.get('ao_no')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 223..224
          webservices/resources/legal.py on lines 226..227

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('ao_requestor'):
                  must_clauses.append(Q('match', requestor_names=kwargs.get('ao_requestor')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 223..224

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('mur_dispositions'):
                  must_clauses.append(Q('term', disposition__data__disposition=kwargs.get('mur_dispositions')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 223..224
          webservices/resources/legal.py on lines 226..227

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('ao_status'):
                  must_clauses.append(Q('match', status=kwargs.get('ao_status')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 156..157
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 226..227

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

          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 7 locations. Consider refactoring.
          Open

              if kwargs.get('mur_no'):
                  must_clauses.append(Q('terms', no=kwargs.get('mur_no')))
          Severity: Major
          Found in webservices/resources/legal.py and 6 other locations - About 35 mins to fix
          webservices/resources/legal.py on lines 158..159
          webservices/resources/legal.py on lines 160..161
          webservices/resources/legal.py on lines 162..163
          webservices/resources/legal.py on lines 214..215
          webservices/resources/legal.py on lines 223..224
          webservices/resources/legal.py on lines 226..227

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

          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