CartoDB/cartodb20

View on GitHub
services/datasources/lib/datasources/search/twitter.rb

Summary

Maintainability
D
2 days
Test Coverage

File twitter.rb has 401 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'json'

require_relative '../util/csv_file_dumper'

require_relative '../../../../twitter-search/twitter-search'
Severity: Minor
Found in services/datasources/lib/datasources/search/twitter.rb - About 5 hrs to fix

    Class Twitter has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

          class Twitter < BaseFileStream
    
            include ::LoggerHelper
    
            # Required for all datasources
    Severity: Minor
    Found in services/datasources/lib/datasources/search/twitter.rb - About 4 hrs to fix

      Method search_by_category has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

              def search_by_category(api, base_filters, category)
                api.params = base_filters
      
                exception = nil
                next_results_cursor = nil
      Severity: Minor
      Found in services/datasources/lib/datasources/search/twitter.rb - 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

      Method search_by_category has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def search_by_category(api, base_filters, category)
                api.params = base_filters
      
                exception = nil
                next_results_cursor = nil
      Severity: Major
      Found in services/datasources/lib/datasources/search/twitter.rb - About 2 hrs to fix

        Method build_queries_from_fields has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def build_queries_from_fields(fields)
                  raise ParameterError.new('missing categories', DATASOURCE_NAME) \
                      if fields[:categories].nil? || fields[:categories].empty?
        
                  queries = []
        Severity: Minor
        Found in services/datasources/lib/datasources/search/twitter.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 build_date_from_fields has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

                def build_date_from_fields(fields, date_type)
                  raise ParameterError.new('missing dates', DATASOURCE_NAME) \
                      if fields[:dates].nil?
        
                  case date_type
        Severity: Minor
        Found in services/datasources/lib/datasources/search/twitter.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 do_search has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def do_search(api_config, redis_storage, filters, stream)
                  threads = {}
                  base_filters = filters.select { |k, v| k != FILTER_CATEGORIES }
        
                  category_totals = {}
        Severity: Minor
        Found in services/datasources/lib/datasources/search/twitter.rb - About 1 hr to fix

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

                  def build_date_from_fields(fields, date_type)
                    raise ParameterError.new('missing dates', DATASOURCE_NAME) \
                        if fields[:dates].nil?
          
                    case date_type
          Severity: Minor
          Found in services/datasources/lib/datasources/search/twitter.rb - About 1 hr to fix

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

                    def initialize(config, user, redis_storage = nil, user_defined_limits={})
                      @service_name = DATASOURCE_NAME
                      @filters = Hash.new
            
                      raise UninitializedError.new('missing user instance', DATASOURCE_NAME) if user.nil?
            Severity: Minor
            Found in services/datasources/lib/datasources/search/twitter.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

            Method build_maxresults_field has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                    def build_maxresults_field(user)
                      if twitter_credit_limits > 0
                        [remaining_quota, TwitterSearch::SearchAPI::MAX_PAGE_RESULTS].min
                      else
                        # user about to hit quota?
            Severity: Minor
            Found in services/datasources/lib/datasources/search/twitter.rb - 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

            There are no issues that match your filters.

            Category
            Status