cantino/huginn

View on GitHub
app/models/agents/website_agent.rb

Summary

Maintainability
F
4 days
Test Coverage

File website_agent.rb has 610 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'nokogiri'
require 'date'

module Agents
  class WebsiteAgent < Agent
Severity: Major
Found in app/models/agents/website_agent.rb - About 1 day to fix

    Method validate_extract_options! has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate_extract_options!
          extraction_type = begin
            extraction_type()
          rescue StandardError
            extraction_type(options)
    Severity: Minor
    Found in app/models/agents/website_agent.rb - About 1 day 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 validate_extract_options! has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def validate_extract_options!
          extraction_type = begin
            extraction_type()
          rescue StandardError
            extraction_type(options)
    Severity: Major
    Found in app/models/agents/website_agent.rb - About 3 hrs to fix

      Class WebsiteAgent has 25 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class WebsiteAgent < Agent
          include WebRequestConcern
      
          can_dry_run!
          can_order_created_events!
      Severity: Minor
      Found in app/models/agents/website_agent.rb - About 2 hrs to fix

        Method extract_xml has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            def extract_xml(doc)
              extract_each { |extraction_details, values|
                case
                when css = extraction_details['css']
                  nodes = doc.css(css)
        Severity: Minor
        Found in app/models/agents/website_agent.rb - 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

        Method validate_options has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            def validate_options
              # Check for required fields
              errors.add(:base,
                         "either url, url_from_event, or data_from_event are required") unless options['url'].present? || options['url_from_event'].present? || options['data_from_event'].present?
              errors.add(:base,
        Severity: Minor
        Found in app/models/agents/website_agent.rb - 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

        Method receive has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def receive(incoming_events)
              interpolate_with_each(incoming_events) do |event|
                existing_payload = interpolated['mode'].to_s == "merge" ? event.payload : {}
        
                if data_from_event = options['data_from_event'].presence
        Severity: Minor
        Found in app/models/agents/website_agent.rb - 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

        Method handle_data has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def handle_data(body, url, existing_payload)
              # Beware, url may be a URI object, string or nil
        
              doc = parse(body)
        
        
        Severity: Minor
        Found in app/models/agents/website_agent.rb - About 1 hr to fix

          Method extract_xml has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def extract_xml(doc)
                extract_each { |extraction_details, values|
                  case
                  when css = extraction_details['css']
                    nodes = doc.css(css)
          Severity: Minor
          Found in app/models/agents/website_agent.rb - About 1 hr to fix

            Method handle_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def handle_data(body, url, existing_payload)
                  # Beware, url may be a URI object, string or nil
            
                  doc = parse(body)
            
            
            Severity: Minor
            Found in app/models/agents/website_agent.rb - About 55 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

            Avoid deeply nested control flow statements.
            Open

                            if re && !re.names.include?(index)
                              errors.add(:base, "no named capture #{index.inspect} found in regexp for #{name.inspect})")
                            end
            Severity: Major
            Found in app/models/agents/website_agent.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              case details['xpath']
                              when String
                                # ok
                              when nil
                                errors.add(:base,
              Severity: Major
              Found in app/models/agents/website_agent.rb - About 45 mins to fix

                Method extract_each has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    def extract_each(&block)
                      interpolated['extract'].each_with_object(Output.new) { |(name, extraction_details), output|
                        if boolify(extraction_details['repeat'])
                          values = Repeater.new { |repeater|
                            block.call(extraction_details, repeater)
                Severity: Minor
                Found in app/models/agents/website_agent.rb - 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

                Avoid deeply nested control flow statements.
                Open

                                rescue StandardError => e
                                  errors.add(:base, "invalid regexp for #{name.inspect}: #{e.message}")
                Severity: Major
                Found in app/models/agents/website_agent.rb - About 45 mins to fix

                  Method check_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def check_url(url, existing_payload = {})
                        unless /\Ahttps?:\/\//i === url
                          error "Ignoring a non-HTTP url: #{url.inspect}"
                          return
                        end
                  Severity: Minor
                  Found in app/models/agents/website_agent.rb - 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

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

                                case details['path']
                                when String
                                  # ok
                                when nil
                                  errors.add(:base,
                  Severity: Minor
                  Found in app/models/agents/website_agent.rb and 1 other location - About 15 mins to fix
                  app/models/agents/website_agent.rb on lines 302..309

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

                  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

                                  case details['xpath']
                                  when String
                                    # ok
                                  when nil
                                    errors.add(:base,
                  Severity: Minor
                  Found in app/models/agents/website_agent.rb and 1 other location - About 15 mins to fix
                  app/models/agents/website_agent.rb on lines 324..331

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

                  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