failmap/admin

View on GitHub
websecmap/map/report.py

Summary

Maintainability
F
6 days
Test Coverage

Function calculate_high_level_stats has a Cognitive Complexity of 116 (exceeds 5 allowed). Consider refactoring.
Open

def calculate_high_level_stats(days: int = 1, countries: List = None, organization_types: List = None):
    log.info("Creating high_level_stats")

    map_configurations = filter_map_configs(countries=countries, organization_types=organization_types)

Severity: Minor
Found in websecmap/map/report.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

File report.py has 715 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import calendar
import logging
from collections import OrderedDict
from copy import deepcopy
from datetime import date, datetime, timedelta
Severity: Major
Found in websecmap/map/report.py - About 1 day to fix

    Function calculate_vulnerability_statistics has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
    Open

    def calculate_vulnerability_statistics(days: int = 366, countries: List = None, organization_types: List = None):
        log.info("Calculation vulnerability graphs")
    
        map_configurations = filter_map_configs(countries=countries, organization_types=organization_types)
    
    
    Severity: Minor
    Found in websecmap/map/report.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

    Cyclomatic complexity is too high in function calculate_high_level_stats. (28)
    Open

    @app.task(queue="reporting")
    def calculate_high_level_stats(days: int = 1, countries: List = None, organization_types: List = None):
        log.info("Creating high_level_stats")
    
        map_configurations = filter_map_configs(countries=countries, organization_types=organization_types)
    Severity: Minor
    Found in websecmap/map/report.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function calculate_vulnerability_statistics. (18)
    Open

    @app.task(queue="reporting")
    def calculate_vulnerability_statistics(days: int = 366, countries: List = None, organization_types: List = None):
        log.info("Calculation vulnerability graphs")
    
        map_configurations = filter_map_configs(countries=countries, organization_types=organization_types)
    Severity: Minor
    Found in websecmap/map/report.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function compose_task. (8)
    Open

    def compose_task(
        organizations_filter: dict = dict(),
        urls_filter: dict = dict(),
        endpoints_filter: dict = dict(),
    ) -> Task:
    Severity: Minor
    Found in websecmap/map/report.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function reduce_to_save_data. (8)
    Open

    def reduce_to_save_data(moments: List[datetime]) -> List[datetime]:
        # reduce to only the dates, easier to work with.
        moments = reduce_to_days(moments)
    
        results = []
    Severity: Minor
    Found in websecmap/map/report.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

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

    def calculate_map_data(days: int = 366, countries: List = None, organization_types: List = None):
        from django.db import OperationalError
    
        log.info("calculate_map_data")
    
    
    Severity: Minor
    Found in websecmap/map/report.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

    Avoid deeply nested control flow statements.
    Open

                        if scan_type in PUBLISHED_SCAN_TYPES:
                            vs.urls = measurement[scan_type]["applicable_urls"]
                            vs.endpoints = measurement[scan_type]["applicable_endpoints"]
                        else:
                            # total
    Severity: Major
    Found in websecmap/map/report.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if scan_type in ENDPOINT_SCAN_TYPES:
                              vs.ok = measurement[scan_type]["ok_endpoints"]
                          elif scan_type in URL_SCAN_TYPES:
                              vs.ok = measurement[scan_type]["ok_urls"]
                          else:
      Severity: Major
      Found in websecmap/map/report.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if url["url"] in noduplicates:
                                continue
                            noduplicates.append(url["url"])
        Severity: Major
        Found in websecmap/map/report.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              for r in url["ratings"]:
                                  # stats over all different ratings
                                  if r["type"] not in measurement["explained"]:
                                      measurement["explained"][r["type"]] = {}
                                      measurement["explained"][r["type"]]["total"] = 0
          Severity: Major
          Found in websecmap/map/report.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if urlrating["url"] in processed_urls:
                                    # log.debug("Removed url because it's already in the report: %s" % urlrating["url"])
                                    continue
            
            
            Severity: Major
            Found in websecmap/map/report.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  for endpoint in url["endpoints"]:
              
                                      # Only add the endpoint once for a series of ratings. And only if the
                                      # ratings is not a repeated finding.
                                      added_endpoint = False
              Severity: Major
              Found in websecmap/map/report.py - About 45 mins to fix

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

                def compose_task(
                    organizations_filter: dict = dict(),
                    urls_filter: dict = dict(),
                    endpoints_filter: dict = dict(),
                ) -> Task:
                Severity: Minor
                Found in websecmap/map/report.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

                                    for rating in urlrating["ratings"]:
                
                                        # log.debug("- type: %s H: %s, M: %s, L: %s" %
                                        #     (rating['type'], rating['high'], rating['medium'], rating['low']))
                
                
                Severity: Major
                Found in websecmap/map/report.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      for endpoint in urlrating["endpoints"]:
                  
                                          for rating in endpoint["ratings"]:
                                              if rating["type"] not in measurement:
                                                  measurement[rating["type"]] = {
                  Severity: Major
                  Found in websecmap/map/report.py - About 45 mins to fix

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

                    def recreate_organization_reports(organizations: List[int]):
                        """Remove organization rating and rebuild a new."""
                    
                        # todo: only for allowed organizations...
                    
                    
                    Severity: Minor
                    Found in websecmap/map/report.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 default_organization_rating has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    def default_organization_rating(organizations: List[int]):
                        """
                        Generate default ratings so all organizations are on the map (as being grey). This prevents
                        empty spots / holes.
                        :return:
                    Severity: Minor
                    Found in websecmap/map/report.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

                    There are no issues that match your filters.

                    Category
                    Status