CenterForOpenScience/waterbutler

View on GitHub

Showing 62 of 92 total issues

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

    def _interpret_query_parameters(self, **kwargs) -> Tuple[str, str, str]:
        """This one hurts.

        Over the life of WB, the github provider has accepted the following parameters to identify
        the ref (commit or branch) that the path entity is to be found on: ``ref``, ``branch``,
Severity: Minor
Found in waterbutler/providers/github/provider.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 on_finish has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def on_finish(self):
        status, method = self.get_status(), self.request.method.upper()

        # If the response code is not within the 200-302 range, the request was a HEAD or OPTIONS,
        # the response code is 202, or the response was a 206 partial request, then no callbacks
Severity: Minor
Found in waterbutler/server/api/v1/provider/__init__.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

File exceptions.py has 252 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
from http import HTTPStatus

from aiohttp.client_exceptions import ContentTypeError

Severity: Minor
Found in waterbutler/core/exceptions.py - About 2 hrs to fix

    Function write_error has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def write_error(self, status_code, exc_info):
            etype, exc, _ = exc_info
    
            finish_args = []
            with sentry_sdk.configure_scope() as scope:
    Severity: Minor
    Found in waterbutler/server/api/v1/core.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 dropbox_conflict_error_handler has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def dropbox_conflict_error_handler(self, data: dict, error_path: str='') -> None:
            """Takes a standard Dropbox error response and an optional path and tries to throw a
            meaningful error based on it.
    
            :param dict data: the error received from Dropbox
    Severity: Minor
    Found in waterbutler/providers/dropbox/provider.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 new_from_response has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def new_from_response(cls, response, base_folder_id, base_folder_metadata=None):
            """Build a new `OneDrivePath` object from a OneDrive API response representing a file or
            folder entity.  Requires the ID of the provider base folder.  Requires base folder metadata
            if base folder is neither the provider root nor the immediate parent of the entity being
            built.
    Severity: Minor
    Found in waterbutler/providers/onedrive/path.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 _merge_dicts has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _merge_dicts(a, b, path=None):
        """"merges b into a
    
        Taken from: http://stackoverflow.com/a/7205107
        """
    Severity: Minor
    Found in waterbutler/core/metrics.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 get_auth_naive has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_auth_naive(self):
            """ Get the obfuscated authentication / authorization credentials from the request.  Return
            a tuple ``(limit_check, auth_key)`` that tells the rate-limiter 1) whether to rate-limit,
            and 2) if so, limit by what key.
    
    
    Severity: Minor
    Found in waterbutler/server/api/v1/provider/ratelimiting.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 _construct_metadata has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _construct_metadata(self, data: dict, path):
            """Take a file/folder metadata response from OneDrive and a path object representing the
            queried path and return a `OneDriveFileMetadata` object if the repsonse represents a file
            or a list of `OneDriveFileMetadata` and `OneDriveFolderMetadata` objects if the response
            represents a folder. """
    Severity: Minor
    Found in waterbutler/providers/onedrive/provider.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 _scrub_headers_for_keen has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _scrub_headers_for_keen(payload, MAX_ITERATIONS=10):
        """ Scrub unwanted characters like \\.\\ from the keys in the keen payload """
    
        scrubbed_payload = {}
        for key in sorted(payload):
    Severity: Minor
    Found in waterbutler/core/remote_logging.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 test has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def test(ctx, verbose=False, types=False, nocov=False, provider=None, path=None):
        """Run full or customized tests for WaterButler.
    
        :param ctx: the ``invoke`` context
        :param verbose: the flag to increase verbosity
    Severity: Minor
    Found in tasks.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 log_file_action has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def log_file_action(action, source, api_version, destination=None, request={},
    Severity: Major
    Found in waterbutler/core/remote_logging.py - About 1 hr to fix

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

          def set_default_headers(self):
              if not self.request.headers.get('Origin'):
                  return
      
              allowed_origin = None
      Severity: Minor
      Found in waterbutler/server/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 _extract_endpoints has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _extract_endpoints(self, data):
              """Pulls both the public and internal cloudfiles urls,
              returned respectively, from the return of tokens
              Very optimized.
              :param dict data: The json response from the token endpoint
      Severity: Minor
      Found in waterbutler/providers/cloudfiles/provider.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 build_url has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def build_url(base: str, *segments, **query) -> str:
          """Build URL with ``'/'`` encoded in path segments and queries for Google Cloud API.
      
          Objects' names in Google Cloud Storage contain ``'/'`` which must be encoded.  WB calls
          :func:`urllib.parse.quote()` with optional argument ``safe=''``.  The default is ``safe='/'``.
      Severity: Minor
      Found in waterbutler/providers/googlecloud/utils.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 rate_limit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def rate_limit(self):
              """ Check with the WB Redis server on whether to rate-limit a request.  Returns a tuple.
              First value is `True` if the limit is reached, `False` otherwise.  Second value is the
              rate-limiting metadata (nbr of requests remaining, time to reset, etc.) if the request was
              rate-limited.
      Severity: Minor
      Found in waterbutler/server/api/v1/provider/ratelimiting.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 _determine_actions has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def _determine_actions(self, resource, provider, request, action=None,
      Severity: Major
      Found in waterbutler/auth/osf/handler.py - About 50 mins to fix

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

        def test(ctx, verbose=False, types=False, nocov=False, provider=None, path=None):
        Severity: Minor
        Found in tasks.py - About 45 mins to fix

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

              def _json_api_links(self, resource):
                  """Update JSON-API links to add commitSha or branch, if available"""
                  links = super()._json_api_links(resource)
          
                  ref = None
          Severity: Minor
          Found in waterbutler/providers/bitbucket/metadata.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 _json_api_links has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _json_api_links(self, resource) -> dict:
                  """Update JSON-API links to add branch, if available"""
                  links = super()._json_api_links(resource)
          
                  ref = None
          Severity: Minor
          Found in waterbutler/providers/gitlab/metadata.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

          Severity
          Category
          Status
          Source
          Language