MihaZelnik/adwordspy

View on GitHub
src/adwordspy/adwords.py

Summary

Maintainability
F
5 days
Test Coverage

File adwords.py has 514 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import time

Severity: Major
Found in src/adwordspy/adwords.py - About 1 day to fix

    Function _iter_selector has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        def _iter_selector(self, service, selector, name):
            """
                Yield a list of entries from `service` using `selector`
            """
            offset = 0
    Severity: Minor
    Found in src/adwordspy/adwords.py - About 6 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

    Function _mutate_operation has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def _mutate_operation(self, service, operations):
    
            tries = 0
            while tries <= self.retries:
                try:
    Severity: Minor
    Found in src/adwordspy/adwords.py - 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

    AdwordsAPI has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class AdwordsAPI(object):
        def __init__(self, account_id, client_id, client_secret, refresh_token, developer_token,
                     version='v201609', page_size=100, retries=3, timesleep=True):
            self.account_id = account_id
            self.client_id = client_id
    Severity: Minor
    Found in src/adwordspy/adwords.py - About 2 hrs to fix

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

          def __init__(self, account_id, client_id, client_secret, refresh_token, developer_token,
      Severity: Major
      Found in src/adwordspy/adwords.py - About 1 hr to fix

        Function download_report_with_awql has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def download_report_with_awql(self, path, query, report_format='CSV', skip_report_header=True,
        Severity: Major
        Found in src/adwordspy/adwords.py - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                      if self.timesleep:
                                          time.sleep(2 ** tries)
                                  elif error['ApiError.Type'] == 'RateExceededError':
          Severity: Major
          Found in src/adwordspy/adwords.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if self.timesleep:
                                            time.sleep(int(error['retryAfterSeconds']))
                                    else:
            Severity: Major
            Found in src/adwordspy/adwords.py - About 45 mins to fix

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

                              for error in errors:
                                  if error['ApiError.Type'] == 'InternalApiError':
                                      tries += 1
                                      if self.timesleep:
                                          time.sleep(2 ** tries)
              Severity: Major
              Found in src/adwordspy/adwords.py and 1 other location - About 5 hrs to fix
              src/adwordspy/adwords.py on lines 110..122

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

              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 error['ApiError.Type'] == 'AuthenticationError':
                                          self._refresh_service(name)
                                          # this will try to get service one more time
                                          tries += self.retries - 1
                                      elif error['ApiError.Type'] == 'InternalApiError':
              Severity: Major
              Found in src/adwordspy/adwords.py and 1 other location - About 5 hrs to fix
              src/adwordspy/adwords.py on lines 78..87

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

              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 3 locations. Consider refactoring.
              Open

                  def get_keywords_by_match_type(self, adgroup_ids, match_types=None):
                      """
                          Get all keywords from `adgroup_ids` based on match_types
                          Args:
                              adgroup_ids (list): list of adgroup ids
              Severity: Major
              Found in src/adwordspy/adwords.py and 2 other locations - About 2 hrs to fix
              src/adwordspy/adwords.py on lines 397..421
              src/adwordspy/adwords.py on lines 503..528

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

              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 3 locations. Consider refactoring.
              Open

                  def get_keywords_by_status(self, adgroup_ids, statuses=None):
                      """
                          Get all keywords from `adgroup_ids` based on statuses
                          Args:
                              adgroup_ids (list): list of adgroup ids
              Severity: Major
              Found in src/adwordspy/adwords.py and 2 other locations - About 2 hrs to fix
              src/adwordspy/adwords.py on lines 397..421
              src/adwordspy/adwords.py on lines 476..501

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

              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 3 locations. Consider refactoring.
              Open

                  def get_text_ads_by_status(self, adgroup_ids, statuses=None):
                      """
                          Get text ads from `adgroup_ids` based on statuses
                          Args:
                              adgroup_ids (list): list of adgroup ids
              Severity: Major
              Found in src/adwordspy/adwords.py and 2 other locations - About 2 hrs to fix
              src/adwordspy/adwords.py on lines 476..501
              src/adwordspy/adwords.py on lines 503..528

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

              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