dnstats/dnstatsio

View on GitHub

Showing 49 of 232 total issues

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

def get_spf_stats(ans: list) -> dict:
    """

    :param ans:
    :return:
Severity: Minor
Found in dnstats/dnsutils/spf.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

Avoid deeply nested control flow statements.
Open

                    if len(sites_chunked_update) >= 100:
                        chunk_count += 1
                        # loop counter to monitor task creation status
                        logger.debug("existing_sites chunk count: {}".format(chunk_count))
                        logger.info("Creating update task: {}".format(chunk_count))
Severity: Major
Found in dnstats/celery.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        for r in ans:
                            if r.startswith('"v=spf'):
                                return r
        return ''
    Severity: Major
    Found in dnstats/dnsutils/spf.py - About 45 mins to fix

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

      def main():
          with open('mx_records.txt', 'r') as f:
              domains = dict()
              for line in f:
                  line = line.replace("{", '').replace('}', '').strip()
      Severity: Minor
      Found in dnstats/data/process_mx.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 get_provider_from_ns_records has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_provider_from_ns_records(ans: list, site: str) -> int:
          if ans:
              ns_string = ''.join(ans).lower()
              if ns_string.endswith(site + '.'):
                  return db_session.query(models.DnsProvider).filter_by(search_regex='Self-hosted').one().id
      Severity: Minor
      Found in dnstats/dnsutils/__init__.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 grade_dmarc has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def grade_dmarc(site_run_id: int):
          site, site_run = get_site_and_site_run(site_run_id)
          records = site_run.j_dmarc_record
          grade = 0
          dmarcs = list()
      Severity: Minor
      Found in dnstats/celery.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

      Avoid deeply nested control flow statements.
      Open

                          if rf != 'afrf':
                              errors.append(DmarcErrors.INVALID_RF_VALUE)
                  elif tag == 'ri':
      Severity: Major
      Found in dnstats/dnsvalidate/dmarc.py - About 45 mins to fix

        Function after_return has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def after_return(self, status, retval, task_id, args, kwargs, einfo):
        Severity: Minor
        Found in dnstats/celery.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if record.startswith('v=spf1 '):
                                  if not has_spf:
                                      for spf_part in record.split(' '):
                                          parts_to_consider.append(spf_part)
                                      has_spf = True
          Severity: Major
          Found in dnstats/dnsvalidate/spf.py - About 45 mins to fix

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

            def _run_report(query: str, report: str, adoption: bool, run_id: int, random_colors=False):
            Severity: Minor
            Found in dnstats/charts/__init__.py - About 35 mins to fix

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

              def extract_spf_from_txt(txt_records: list, domain: str):
                  spfs = list()
                  errors = list()
                  if not txt_records:
                      errors.append(SpfError.NO_SPF_FOUND)
              Severity: Minor
              Found in dnstats/dnsvalidate/spf.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

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

              def grade(mxs: list, domain: str) -> [int, list]:
                  mx = Mx(mxs)
              
                  if MXErrors.NO_MX_RECORDS in mx.errors or len(mx.valid_mx_records) == 0:
                      return 0, mx.errors
              Severity: Minor
              Found in dnstats/grading/mx.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

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

              def query_name_server(dns_server_ips: list, domain: str, request_type: str) -> []:
                  """
                  Do a query with a given name server, domain, and request type
              
                  :param dns_server_ips: IP addresses of the name servers to use
              Severity: Minor
              Found in dnstats/dnsutils/__init__.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

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

              def grade(bimis: list, dmarcs: list, domain: str) -> [int, ()]:
                  if not bimis:
                      return 0, [BimiErrors.N0_BIMI_RECORDS]
              
                  the_bimis = []
              Severity: Minor
              Found in dnstats/grading/bimi.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 'B-'
              Severity: Major
              Found in dnstats/grading/__init__.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return 'D-'
                Severity: Major
                Found in dnstats/grading/__init__.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return result
                  Severity: Major
                  Found in dnstats/dnsvalidate/bimi.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return 'C-'
                    Severity: Major
                    Found in dnstats/grading/__init__.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                              return 'D'
                      Severity: Major
                      Found in dnstats/grading/__init__.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return max(final_grade - (5 * len(soa.errors)), 0), soa.errors
                        Severity: Major
                        Found in dnstats/grading/soa.py - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language