twitterdev/twitter-python-ads-sdk

View on GitHub

Showing 12 of 77 total issues

File creative.py has 371 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright (C) 2015 Twitter, Inc.

"""Container for all creative management logic used by the Ads API SDK."""

import json
Severity: Minor
Found in twitter_ads/creative.py - About 4 hrs to fix

    File campaign.py has 354 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    # Copyright (C) 2015 Twitter, Inc.
    
    """Container for all campaign management logic used by the Ads API SDK."""
    
    from twitter_ads.enum import TRANSFORM
    Severity: Minor
    Found in twitter_ads/campaign.py - About 4 hrs to fix

      Function __oauth_request has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          def __oauth_request(self):
              headers = {'user-agent': self.__user_agent()}
              if 'headers' in self.options:
                  headers.update(self.options['headers'].copy())
      
      
      Severity: Minor
      Found in twitter_ads/http.py - About 4 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 test_rate_limit.py has 277 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import responses
      import unittest
      import time
      
      from tests.support import with_resource, with_fixture, characters
      Severity: Minor
      Found in tests/test_rate_limit.py - About 2 hrs to fix

        Function test_analytics_async has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        def test_analytics_async():
            responses.add(responses.GET,
                          with_resource('/' + API_VERSION + '/accounts/2iqph'),
                          body=with_fixture('accounts_load'),
                          content_type='application/json')
        Severity: Minor
        Found in tests/test_analytics_async.py - About 1 hr to fix

          Function from_response has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def from_response(self, response, headers=None):
                  """
                  Populates a given objects attributes from a parsed JSON API response.
                  This helper handles all necessary type coercions as it assigns
                  attribute values.
          Severity: Minor
          Found in twitter_ads/resource.py - 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

          Function __from_response has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def __from_response(self, response):
                  self._next_cursor = response.body.get('next_cursor', None)
                  if 'total_count' in response.body:
                      self._total_count = int(response.body['total_count'])
          
          
          Severity: Minor
          Found in twitter_ads/cursor.py - 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

          Function to_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def to_params(self):
                  """
                  Generates a Hash of property values for the current object. This helper
                  handles all necessary type coercions as it generates its output.
                  """
          Severity: Minor
          Found in twitter_ads/resource.py - 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

          Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(self,
          Severity: Minor
          Found in twitter_ads/client.py - About 35 mins to fix

            Function to_time has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def to_time(time, granularity):
                """Returns a truncated and rounded time string based on the specified granularity."""
                if not granularity:
                    if type(time) is datetime.date:
                        return format_date(time)
            Severity: Minor
            Found in twitter_ads/utils.py - 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

            Avoid too many return statements within this function.
            Open

                    return format_time(time)
            Severity: Major
            Found in twitter_ads/utils.py - About 30 mins to fix

              Function batch_save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def batch_save(klass, account, objs):
                      """
                      Makes batch request(s) for a passed in list of objects
                      """
              
              
              Severity: Minor
              Found in twitter_ads/resource.py - 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