fairplaysk/datacamp

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

Summary

Maintainability
F
1 wk
Test Coverage

Method suppliers_information has a Cognitive Complexity of 300 (exceeds 5 allowed). Consider refactoring.
Open

      def suppliers_information
        suppliers = []

        case document_format
          when :format1
Severity: Minor
Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 6 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 suppliers_information has 242 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def suppliers_information
        suppliers = []

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

    Avoid deeply nested control flow statements.
    Open

                        if contract_name_element.name == "div" && contract_name_element.attributes["class"].value == "textArea"
                          supplier_hash[:contract_name] = contract_name_element.xpath(".//span[2]").inner_text.strip
                        end
    Severity: Major
    Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                        elsif code_text.match(/V\.*.*?[^\d]1[^\d]$/) && (header_text.match(/Dátum/) || header_text.match(/DÁTUM/))
                          contract_date_element = tr.xpath(".//span[@class='hodnota']")
                          supplier_hash[:contract_date] = parse_date(contract_date_element.inner_text.strip)
      
                        elsif code_text.match(/V\.*.*?[^\d]2[^\d]$/) && (header_text.match(/Počet prijatých/) || header_text.match(/POČET PRIJATÝCH/))
      Severity: Major
      Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                              suppliers << supplier_hash if supplier_hash[:supplier_name]
        Severity: Major
        Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if supplier_hash.any?
                                suppliers << supplier_hash if supplier_hash[:supplier_name]
                                supplier_hash = {}
                              end
          Severity: Major
          Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                  suppliers << supplier_hash if supplier_hash[:supplier_name]
            Severity: Major
            Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if supplier_hash.any?
                                    suppliers << supplier_hash if supplier_hash[:supplier_name]
                                    supplier_hash = {}
                                  end
              Severity: Major
              Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                  elsif code_text.match(/V\.*.*?[^\d]2[^\d]$/) && (header_text.match(/Počet predložených ponúk/) || header_text.match(/Počet uchádzačov, ktorí predložili ponuku/))
                                    offers_total_count_element = next_element(code.parent)
                                    supplier_hash[:offers_total_count] = offers_total_count_element.inner_text.strip.to_i
                
                                  elsif code_text.match(/V\.*.*?[^\d]1[^\d]$/) && (header_text.match(/Počet uchádzačov/))
                Severity: Major
                Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 45 mins to fix

                  Consider simplifying this complex logical expression.
                  Open

                                    elsif (code_text.match(/V\.*.*?[^\d]3[^\d]$/) || code_text.match(/V\.*.*?[^\d]4[^\d]$/)) && (header_text.match(/Názov a adresa/) || header_text.match(/NÁZOV A ADRESA/) || header_text.match(/Meno(.*)adresa(.*)víťaza/))
                                      supplier_information = next_element(code.parent)
                                      supplier_hash[:supplier_name] = supplier_information.xpath("./span[@class='titleValue']/span[1]").inner_text.strip
                                      supplier_hash[:supplier_organisation_code] = supplier_information.xpath(".//span[@class='titleValue']/span[3]").inner_text.strip
                  
                  
                  Severity: Major
                  Found in lib/etl/vvo_v2/suppliers_information_parser.rb - About 40 mins to fix

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

                                          if span.inner_text.strip.start_with?('Telefón')
                                            supplier_hash[:supplier_phone] = span.next_sibling.next_sibling.inner_text.strip
                                          elsif span.inner_text.strip.start_with?('Fax')
                                            supplier_hash[:supplier_fax] = span.next_sibling.next_sibling.inner_text.strip
                                          elsif span.inner_text.strip.start_with?('Email')
                    Severity: Major
                    Found in lib/etl/vvo_v2/suppliers_information_parser.rb and 1 other location - About 1 hr to fix
                    lib/etl/vvo_v2/customer_information_parser.rb on lines 26..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 56.

                    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

                                              if price_hash[:price_range]
                                                supplier_hash[:final_price_min] = price_hash[:price_min]
                                                supplier_hash[:final_price_max] = price_hash[:price_max]
                                                supplier_hash[:final_price_range] = true
                                              else
                    Severity: Minor
                    Found in lib/etl/vvo_v2/suppliers_information_parser.rb and 1 other location - About 30 mins to fix
                    lib/etl/vvo_v2/suppliers_information_parser.rb on lines 121..127

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

                    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

                                          if header.match(/Telefón/)
                                            supplier_hash[:supplier_phone] = content
                                          elsif header.match(/Fax/)
                                            supplier_hash[:supplier_fax] = content
                                          elsif header.match(/E-mail/)
                    Severity: Minor
                    Found in lib/etl/vvo_v2/suppliers_information_parser.rb and 1 other location - About 30 mins to fix
                    lib/etl/vvo_v2/customer_information_parser.rb on lines 90..98

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

                    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

                                              if price_hash[:price_range]
                                                supplier_hash[:final_price_min] = price_hash[:price_min]
                                                supplier_hash[:final_price_max] = price_hash[:price_max]
                                                supplier_hash[:final_price_range] = true
                                              else
                    Severity: Minor
                    Found in lib/etl/vvo_v2/suppliers_information_parser.rb and 1 other location - About 30 mins to fix
                    lib/etl/vvo_v2/suppliers_information_parser.rb on lines 258..264

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

                    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