twitterdev/twitter-ruby-ads-sdk

View on GitHub

Showing 16 of 29 total issues

Method oauth_request has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def oauth_request
      request  = http_request
      consumer = OAuth::Consumer.new(@client.consumer_key, @client.consumer_secret, site: domain)
      token    = OAuth::AccessToken.new(consumer, @client.access_token, @client.access_token_secret)
      request.oauth!(consumer.http, consumer, token)
Severity: Minor
Found in lib/twitter-ads/http/request.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

File metric_filtering.rb has 278 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'twitter-ads'
require 'yaml'

module TwitterAds

Severity: Minor
Found in examples/metric_filtering.rb - About 2 hrs to fix

    Class Account has 22 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Account
    
        include TwitterAds::DSL
    
        attr_reader :client
    Severity: Minor
    Found in lib/twitter-ads/account.rb - About 2 hrs to fix

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

            def to_params
              params = {}
              self.class.properties.each do |name, type|
                value = instance_variable_get("@#{name}") || send(name)
                next if value.nil?
      Severity: Minor
      Found in lib/twitter-ads/resources/dsl.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 oauth_request has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def oauth_request
            request  = http_request
            consumer = OAuth::Consumer.new(@client.consumer_key, @client.consumer_secret, site: domain)
            token    = OAuth::AccessToken.new(consumer, @client.access_token, @client.access_token_secret)
            request.oauth!(consumer.http, consumer, token)
      Severity: Minor
      Found in lib/twitter-ads/http/request.rb - About 1 hr to fix

        Method filter_placements has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def filter_placements(metrics, placements)
              # return, nothing to exclude
              return if placements.include?(:all_on_twitter) && placements.include?(:publisher_network)
        
              # remove all TAP-related metrics unless publisher_network
        Severity: Minor
        Found in examples/metric_filtering.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 batch_save has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def batch_save(account, objs)
                resource = self::RESOURCE_BATCH % { account_id: account.id }
        
                json_body = []
        
        
        Severity: Minor
        Found in lib/twitter-ads/resources/batch.rb - About 1 hr to fix

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

                def load(account, card_uris = nil, card_id = nil, with_deleted = nil, opts = {})
                  if (card_uris && card_id) || (card_uris.nil? && card_id.nil?)
                    raise ArgumentError.new('card_uris and card_id are exclusive parameters. ' \
                                       'Please supply one or the other, but not both.')
                  end
          Severity: Minor
          Found in lib/twitter-ads/creative/cards_fetch.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

          Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def initialize(consumer_key, consumer_secret, access_token, access_token_secret, opts = {})
          Severity: Minor
          Found in lib/twitter-ads/client.rb - About 35 mins to fix

            Method load has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  def load(account, card_uris = nil, card_id = nil, with_deleted = nil, opts = {})
            Severity: Minor
            Found in lib/twitter-ads/creative/cards_fetch.rb - About 35 mins to fix

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

                    def from_response(object, headers = nil)
                      if !headers.nil?
                        TwitterAds::Utils.extract_response_headers(headers).each { |key, value|
                          singleton_class.class_eval { attr_accessor key }
                          instance_variable_set("@#{key}", value)
              Severity: Minor
              Found in lib/twitter-ads/resources/dsl.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

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

                    def extract_response_headers(headers)
                      values = {}
                      # only get "X-${name}" custom response headers
                      headers.each { |key, value|
                        if key =~ /^x-/
              Severity: Minor
              Found in lib/twitter-ads/utils.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

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

                  def write_log(object)
                    if object.respond_to?(:code)
                      @client.logger.info("Status: #{object.code} #{object.message}")
                    else
                      @client.logger.info("Send: #{object.method} #{domain}#{@resource} #{@options[:params]}")
              Severity: Minor
              Found in lib/twitter-ads/http/request.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

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

                  def initialize(*args)
                    if args.size == 1 && args[0].respond_to?(:body) && args[0].respond_to?(:code)
                      @response = args[0]
                      @code     = args[0].code
                      @details  = args[0].body[:errors] if args[0].body.is_a?(Hash) && args[0].body[:errors]
              Severity: Minor
              Found in lib/twitter-ads/error.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

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

                    def flatten_params(args)
                      params = args
                      params.each { |key, value|
                        if value.is_a?(Array)
                          next if value.empty?
              Severity: Minor
              Found in lib/twitter-ads/utils.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

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

                    def validate
                      details = []
              
                      unless @line_item_id
                        details << { code: 'MISSING_PARAMETER',
              Severity: Minor
              Found in lib/twitter-ads/creative/promoted_tweet.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

              Severity
              Category
              Status
              Source
              Language