fairplaysk/datacamp

View on GitHub
lib/etl/vvo_v2/contract_information_parser.rb

Summary

Maintainability
F
1 wk
Test Coverage

Method contract_information has a Cognitive Complexity of 273 (exceeds 5 allowed). Consider refactoring.
Open

      def contract_information
        contract_information_hash = {}

        case document_format
          when :format1
Severity: Minor
Found in lib/etl/vvo_v2/contract_information_parser.rb - About 5 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

Method contract_information has 219 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def contract_information
        contract_information_hash = {}

        case document_format
          when :format1
Severity: Major
Found in lib/etl/vvo_v2/contract_information_parser.rb - About 1 day to fix

    Avoid deeply nested control flow statements.
    Open

                        next unless tr_place_element
    Severity: Major
    Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                        elsif code_text.match(/^II.1.3/) && header_text.match(/Oznámenie zahŕňa/)
                          tr_general_contract = tr
                          if tr_general_contract.xpath(".//td[2]//span[@class='hodnota']").empty?
                            tr_general_contract = tr.next_element
                          end
      Severity: Major
      Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                              if category_element.inner_text.strip.blank?
                                category_element = category_element.next_sibling
                              end
        Severity: Major
        Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if type_element.empty?
                                tr_type_element = next_element(tr_type_element)
                                type_element = tr_type_element.xpath(".//span[@class='hodnota']")
                              end
          Severity: Major
          Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                  if nuts_element.xpath(".//div").any?
                                    contract_information_hash[:nuts_code] = nuts_element.xpath(".//div").inner_text
                                  else
                                    contract_information_hash[:nuts_code] = next_element(nuts_element).inner_text.strip
                                  end
            Severity: Major
            Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if dictionary_element.xpath(".//div[2]").inner_text.match(/Doplňujúce predmety/) && dictionary_element.xpath(".//div[3]").any?
                                    dictionary_additional_subjects = dictionary_element.xpath(".//div[3]").inner_text.match(/Hlavný slovník: (.*)/)
                                    if dictionary_additional_subjects && dictionary_additional_subjects.size > 1
                                      contract_information_hash[:dictionary_additional_subjects] = dictionary_additional_subjects[1].strip
                                    end
              Severity: Major
              Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                      if type_element.next_sibling.next_sibling.inner_text.match(/Kategória služby číslo/)
                                        category_element = type_element.next_sibling.next_sibling
                                        contract_information_hash[:project_category] = category_element.xpath(".//span[2]").inner_text.strip
                                      else #237455
                                        category_element = type_element
                Severity: Major
                Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if place_header.match(/V prípade zmluvy/)
                                        tr_place_element = next_element(tr_place_element)
                                        place_header = tr_place_element.xpath(".//span[@class='podnazov']").inner_text
                                      end
                  Severity: Major
                  Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if project_type_exceptions.include?(project_type)
                                          contract_information_hash[:project_type] = project_type_exceptions[project_type]
                                          contract_information_hash[:project_category] = project_type
                                          tr_category_element = tr_type_element
                                        elsif category_number
                    Severity: Major
                    Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                            if category_element.inner_text.match(/Kategórie služieb sú uvedené v prílohe C1/)
                                              content = category_element.xpath(".//span[2]").inner_text.strip
                                            elsif category_element.inner_text.match(/Kategória služby číslo/)
                                              category_element = next_element(category_element)
                                              content = category_element.xpath(".//span[2]").inner_text.strip
                      Severity: Major
                      Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                              if type_element.inner_text.match(/Tovary/) && category_element.inner_text.match(/Tovary/)
                                                category_element = next_element(category_element)
                                                place_is_next = true
                                              end
                        Severity: Major
                        Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                              if project_type_matches
                                                project_type = project_type_matches[2]
                                              end
                          Severity: Major
                          Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                next unless tr_nuts_element
                            Severity: Major
                            Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                  category_number = Integer(project_type) rescue nil
                              Severity: Major
                              Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                    if dictionary_main_subjects && dictionary_main_subjects.size > 1
                                                      contract_information_hash[:dictionary_main_subjects] = dictionary_main_subjects[1].strip
                                                    end
                                Severity: Major
                                Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                      if place_header.match(/miesto/) || place_header.match(/stavenisko/)
                                                        contract_information_hash[:place_of_performance] = strip_last_point(tr_place_element.xpath(".//span[@class='hodnota']").inner_text.strip)
                                                      end
                                  Severity: Major
                                  Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                        if nuts_header.match(/NUTS/)
                                                          tr_nuts_content_element = next_element(tr_nuts_element)
                                                          nuts_code = tr_nuts_content_element.xpath(".//span[@class='hodnota']").inner_text.strip
                                                          contract_information_hash[:nuts_code] = strip_last_point(nuts_code)
                                                        end
                                    Severity: Major
                                    Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                            if place_element.inner_text.strip.blank?
                                                              place_element = place_element.next_sibling
                                                            end
                                      Severity: Major
                                      Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                          elsif code_text.match(/^II.1.6/) && (header_text.match(/Informácie o rámcovej dohode/) || header_text.match(/GPA/))
                                                            gpa_agreement = code.parent.next_sibling.next_sibling.xpath(".//span")
                                                            contract_information_hash[:gpa_agreement] = !gpa_agreement.inner_text.match(/Nie/)
                                        Severity: Major
                                        Found in lib/etl/vvo_v2/contract_information_parser.rb - About 45 mins to fix

                                          There are no issues that match your filters.

                                          Category
                                          Status