CIMAC-CIDC/cidc-api-gae

View on GitHub

Showing 14 of 16 total issues

Function _run_metadata_migration has a Cognitive Complexity of 29 (exceeds 10 allowed). Consider refactoring.
Open

def _run_metadata_migration(
    metadata_migration: Callable[[dict], MigrationResult],
    use_upload_jobs_table: bool,
    gcs_tasks: RollbackableQueue,
    session: Session,
Severity: Minor
Found in cidc_api/models/migrations.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

DownloadableFiles has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class DownloadableFiles(CommonColumns):
    """
    Store required fields from:
    https://github.com/CIMAC-CIDC/cidc-schemas/blob/master/cidc_schemas/schemas/artifacts/artifact_core.json
    """
Severity: Minor
Found in cidc_api/models/models.py - About 2 hrs to fix

    Function _change_download_permissions has a Cognitive Complexity of 19 (exceeds 10 allowed). Consider refactoring.
    Open

        def _change_download_permissions(
            trial_id: str, upload_type: str, grant: bool, session: Session
        ) -> None:
            """
            Allows for widespread granting/revoking of existing download permissions in GCS ACL
    Severity: Minor
    Found in cidc_api/models/models.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 _remove_optional_uuid_recursive has a Cognitive Complexity of 18 (exceeds 10 allowed). Consider refactoring.
    Open

    def _remove_optional_uuid_recursive(target: dict, uuid: str):
        """
        If target contains an item : dict with {"upload_placeholder":uuid}, removes that item and returns the modified target
        If no such item is found, continues recursively as depth first search
        If the uuid is never found, returns the target unchanged
    Severity: Minor
    Found in cidc_api/resources/upload_jobs.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 inner has a Cognitive Complexity of 16 (exceeds 10 allowed). Consider refactoring.
    Open

        def inner(f):
            @wraps(f)
            def wrapped(*args, **kwargs):
                logger.info(f"upload_handler({f.__name__}) started")
                template, xlsx_file = extract_schema_and_xlsx(allowed_types)
    Severity: Minor
    Found in cidc_api/resources/upload_jobs.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 unmarshal_request has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
    Open

    def unmarshal_request(schema: BaseSchema, kwarg_name: str, load_sqla: bool = True):
        """
        Generate a decorator that will load and validate the JSON body of
        the current request object as an instance of `schema` and pass
        the loaded instance to the decorated function as a keyword argument
    Severity: Minor
    Found in cidc_api/shared/rest_utils.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 insert has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

        def insert(
            self,
            session: Session,
            commit: bool = True,
        ) -> None:
    Severity: Minor
    Found in cidc_api/models/models.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 create has 8 arguments (exceeds 6 allowed). Consider refactoring.
    Open

        def create(
    Severity: Major
    Found in cidc_api/models/models.py - About 45 mins to fix

      Function create_from_blob has 7 arguments (exceeds 6 allowed). Consider refactoring.
      Open

          def create_from_blob(
      Severity: Major
      Found in cidc_api/models/models.py - About 35 mins to fix

        Function is_valid_transition has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
        Open

            def is_valid_transition(
                cls, current: str, target: str, is_manifest: bool = False
            ) -> bool:
                """
                Enforce logic about which state transitions are valid. E.g.,
        Severity: Minor
        Found in cidc_api/models/models.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 True
        Severity: Major
        Found in cidc_api/models/models.py - About 30 mins to fix

          Function authorize has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

          def authorize(
              user: Users, allowed_roles: List[str], resource: str, method: str
          ) -> bool:
              """Check if the current user is authorized to act on the current request's resource.
              Raises Unauthorized
          Severity: Minor
          Found in cidc_api/shared/auth.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

          Function _encode_and_publish has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

          def _encode_and_publish(content: str, topic: str) -> Future:
              """Convert `content` to bytes and publish it to `topic`."""
              pubsub_publisher = pubsub.PublisherClient()
              topic = pubsub_publisher.topic_path(GOOGLE_CLOUD_PROJECT, topic)
              data = bytes(content, "utf-8")
          Severity: Minor
          Found in cidc_api/shared/gcloud_client.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

          Function build_file_filter has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
          Open

              def build_file_filter(
                  trial_ids: List[str] = [], facets: List[List[str]] = [], user: Users = None
              ) -> Callable[[Query], Query]:
                  """
                  Build a file filter function based on the provided parameters. The resultant
          Severity: Minor
          Found in cidc_api/models/models.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