Futsch1/form-analyzer

View on GitHub

Showing 14 of 15 total issues

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

def pdf_to_image(folder_or_filename: str, dpi: int = 400, poppler_path: str = None,
                 image_processor: ImageProcessor = lambda image_index, img: [ProcessedImage(img, '')]):
    """
    Converts PDF files in a folder to PNG images.

Severity: Minor
Found in form_analyzer/conversion.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 values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def values(self, form_fields: FieldList) -> typing.List[FormValue]:
        filtered_fields = self.filter.filter(form_fields)
        if len(filtered_fields):
            form_value = FormValue('', filtered_fields[0].page, False)

Severity: Minor
Found in form_analyzer/selectors/text_fields.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

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

    def __init__(self, selections: typing.List[str], filter_: Filter, alternative: typing.Union['TextField', 'TextFieldWithCheckbox'] = None,
Severity: Minor
Found in form_analyzer/selectors/select_base.py - About 35 mins to fix

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

        def __init__(self, aws_region_name: str = None,
    Severity: Minor
    Found in form_analyzer/textract.py - About 35 mins to fix

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

          def __form_value_from_match(self, field_with_page: FieldWithPage) -> FormValue:
              tx_field = field_with_page.field
              uncertain = tx_field.confidence < 40
      
              if tx_field.value is not None and tx_field.value.text not in ['NOT_SELECTED', 'SELECTED']:
      Severity: Minor
      Found in form_analyzer/selectors/text_fields.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 __get_value_if_no_selection has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __get_value_if_no_selection(self, form_fields: FieldList) -> FormValue:
              # No selection found, try alternatives
              not_found_match = Select.SelectionMatch(Match.NOT_FOUND)
      
              # Alternative field given, take that one.
      Severity: Minor
      Found in form_analyzer/selectors/single_select.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 __check_exact_or_part_match has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __check_exact_or_part_match(self, matches) -> bool:
              match_found = False
              for index, match in enumerate(self.selection_matches):
                  if match.match in [Match.EXACT_SELECTED, Match.SIMILAR_SELECTED]:
                      matches[index + 1] = FormValue('1' + ('?' if match.uncertain else ''), match.page, match.uncertain)
      Severity: Minor
      Found in form_analyzer/selectors/multi_select.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 dump_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def dump_fields(form_folder_or_json_file: str, form_description_module_name: typing.Optional[str] = None, target_directory: str = None):
          """
          Dumps the analyzed fields from AWS Textract to text files to support debugging.
      
          :param form_folder_or_json_file: Folder with the AWS Textract result files or a AWS Textract result file
      Severity: Minor
      Found in form_analyzer/analyze.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 __form_value_from_match has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def __form_value_from_match(field_with_page: FieldWithPage) -> FormValue:
              tx_field = field_with_page.field
              uncertain = tx_field.confidence < 40
      
              if tx_field.value.text == 'NOT_SELECTED':
      Severity: Minor
      Found in form_analyzer/selectors/text_fields.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 __check_exact_match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __check_exact_match(self, simple_selection: str, index: int, simple_fields: typing.List[SimpleField]) -> bool:
              for simple_field in simple_fields:
                  if simple_field.key == simple_selection:
                      self.selection_matches[index] = Select.SelectionMatch(
                          Match.EXACT_SELECTED if simple_field.selected else Match.EXACT_NOT_SELECTED,
      Severity: Minor
      Found in form_analyzer/selectors/select_base.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_similar_match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __check_similar_match(self, simple_selection: str, index: int, simple_fields: typing.List[SimpleField]) -> bool:
              match_found = False
              max_ratio = 0.9
              # Second pass: similar match
              for simple_field in simple_fields:
      Severity: Minor
      Found in form_analyzer/selectors/select_base.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_part_match has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def __check_part_match(self, simple_selection: str, index: int, simple_fields: typing.List[SimpleField]):
              for simple_field in simple_fields:
                  if simple_field.key in simple_selection:
                      self.selection_matches[index] = Select.SelectionMatch(
                          Match.SIMILAR_SELECTED if simple_field.selected else Match.SIMILAR_NOT_SELECTED,
      Severity: Minor
      Found in form_analyzer/selectors/select_base.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 _filter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def _filter(self, fields: FieldList) -> FieldList:
              filtered_fields = []
              for field in fields:
                  tx_field = field.field
                  if (self.__horizontal is None or self.__horizontal[0] < tx_field.geometry.boundingBox.left <
      Severity: Minor
      Found in form_analyzer/filters.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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def parse(path_or_file: str, form_pages: FormPages) -> typing.List[ParsedForm]:
          file_names = sorted(glob.glob(path_or_file + '/*.json')) if os.path.isdir(path_or_file) else [path_or_file]
      
          from form_analyzer import form_analyzer_logger
      
      
      Severity: Minor
      Found in form_analyzer/form_parser.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

      Severity
      Category
      Status
      Source
      Language