dnstats/dnstatsio

View on GitHub

Showing 49 of 232 total issues

Function _validate_spf has a Cognitive Complexity of 134 (exceeds 5 allowed). Consider refactoring.
Open

def _validate_spf(spf: str, domain: str) -> {}:
    errors = list()
    if not spf.startswith('v=spf1 '):
        errors.append(SpfError.INVALID_RECORD_START)
    parts = spf.split(' ')
Severity: Minor
Found in dnstats/dnsvalidate/spf.py - About 2 days 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 validate has a Cognitive Complexity of 77 (exceeds 5 allowed). Consider refactoring.
Open

def validate(dmarc_result_set: list) -> dict:
    dmarc_record_values = dict()
    tag_count = dict()
    errors = list()
    if len(dmarc_result_set) < 1:
Severity: Minor
Found in dnstats/dnsvalidate/dmarc.py - About 1 day 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 validate has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

def validate(caa_result_set: list, domain: str) -> dict:
    """
    Validate a CAA record set based on RFC 8659

    :param caa_result_set: a list of CAA records as str
Severity: Minor
Found in dnstats/dnsvalidate/caa.py - About 1 day 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 celery.py has 387 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import os

from celery import Celery, Task
from celery.canvas import chain, group
Severity: Minor
Found in dnstats/celery.py - About 5 hrs to fix

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

    def get_dmarc_stats(ans):
        aggregate = False
        forensic = False
        dmarc = False
        policy = ""
    Severity: Minor
    Found in dnstats/dnsutils/__init__.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 seed.py has 331 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import csv
    
    import dnstats.db.models as models
    from dnstats.db import db_session
    
    
    Severity: Minor
    Found in dnstats/db/seed.py - About 3 hrs to fix

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

          def _validate(self) -> {}:
              result = {}
              errors = []
              validated_records = []
              if not self.ns_records or len(self.ns_records) == 0:
      Severity: Minor
      Found in dnstats/dnsvalidate/ns.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

      Function _get_redirect_record has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

      def _get_redirect_record(record):
          record = record.replace('"', '')
          parts = record.split(' ')
          for part in parts:
              if part.startswith('redirect='):
      Severity: Minor
      Found in dnstats/dnsutils/spf.py - 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

      Function _validate has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def _validate(self) -> dict:
              result = dict()
              result['errors'] = []
              result['records'] = []
              if not self.mx_records or len(self.mx_records) == 0:
      Severity: Minor
      Found in dnstats/dnsvalidate/mx.py - 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

      Function _validate has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def _validate(self, records: list) -> dict:
              result = {}
              self.errors = []
              if not records or len(records) <= 0:
                  self.errors.append(BimiErrors.N0_BIMI_RECORDS)
      Severity: Minor
      Found in dnstats/dnsvalidate/bimi.py - 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

      Function import_list has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      def import_list():
          new_sites = setup_import_list(logger)
      
          existing_sites = dict()
          with engine.connect() as connection:
      Severity: Minor
      Found in dnstats/celery.py - 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

      Function percent_to_letter has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def percent_to_letter(percent: float):
          if percent > 100.0:
              return 'A+'
          elif percent >= 93.0:
              return 'A'
      Severity: Minor
      Found in dnstats/grading/__init__.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 site_stat has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def site_stat(site_id: int, run_id: int):
          logger.debug('start site stat site {} run id {}'.format(site_id, run_id))
          result = dict()
          result['start_time'] = datetime.datetime.now()
          site = db_session.query(models.Site).filter(models.Site.id == site_id).scalar()
      Severity: Minor
      Found in dnstats/celery.py - About 1 hr to fix

        Function caa_stats has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def caa_stats(ans):
            has_reporting = False
            has_caa = False
            allows_wildcard = False
            issue_count = 0
        Severity: Minor
        Found in dnstats/dnsutils/__init__.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 grade has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        def grade(dmarcs: list, domain: str) -> [int, ()]:
            current_grade = 0
            dmarc = Dmarc(dmarcs)
            if dmarc.errors.__contains__(DmarcErrors.INVALID_DMARC_RECORD_START):
                return 0, dmarc.errors
        Severity: Minor
        Found in dnstats/grading/dmarc.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 validate has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def validate(self) -> {}:
                result = {}
                errors = []
                if len(self.soas) == 0:
                    errors.append(SoaErrors.NO_SOA)
        Severity: Minor
        Found in dnstats/dnsvalidate/soa.py - About 1 hr to fix

          Function create_reports has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          def create_reports(run_id: int):
              spf_adoption_query = "select count(*) from site_runs sr " \
                                   "where sr.run_id = {} and sr.has_spf is true".format(run_id)
          
              securitytxt_adoption_query = "select count(*) from site_runs sr " \
          Severity: Minor
          Found in dnstats/charts/__init__.py - About 1 hr to fix

            Function publish_reports has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            def publish_reports(run_id: int):
                # sr is the alias for site_runs table
                reports = list()
                reports.append({'query': 'sr.mx_records is not null', 'name': 'mx_domains', 'type': 'list'})
                reports.append({'query': 'sr.mx_records is null', 'name': 'no_mx_domains', 'type': 'list'})
            Severity: Minor
            Found in dnstats/celery.py - About 1 hr to fix

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

              def grade(spfs: list, domain: str, has_mx: True) -> [int, list]:
                  """
                  Grade a given SPF for a given domain.
                  :param spfs: a list of txt records for the apex
                  :param domain: domain of the given SPF record
              Severity: Minor
              Found in dnstats/grading/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

              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

              Severity
              Category
              Status
              Source
              Language