CenterForOpenScience/waterbutler

View on GitHub

Showing 92 of 92 total issues

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        for part in parts[:-1]:
            if part not in current:
                current[part] = {}
            current = current[part]
Severity: Major
Found in waterbutler/core/metrics.py and 1 other location - About 1 hr to fix
waterbutler/core/metrics.py on lines 109..112

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 44.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        for part in parts[:-1]:
            if part not in current:
                current[part] = {}
            current = current[part]
Severity: Major
Found in waterbutler/core/metrics.py and 1 other location - About 1 hr to fix
waterbutler/core/metrics.py on lines 123..126

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 44.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        @property
        def path(self):
            return '/' + strip_char(self.raw['Key'], self.raw.get('base_folder', ''))
    Severity: Major
    Found in waterbutler/providers/s3/metadata.py and 1 other location - About 1 hr to fix
    waterbutler/providers/s3/metadata.py on lines 110..112

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 39.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

        @property
        def path(self):
            return '/' + strip_char(self.raw['Key'], self.raw.get('base_folder', ''))
    Severity: Major
    Found in waterbutler/providers/s3/metadata.py and 1 other location - About 1 hr to fix
    waterbutler/providers/s3/metadata.py on lines 69..71

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 39.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          def new_subrecord(self, name):
              """Creates and saves a new subrecord.  The new subrecord will have its category set to the
              parent subrecord's ``name``.  ex::
      
                  parent = MetricsRecord('foo')
      Severity: Minor
      Found in waterbutler/core/metrics.py and 1 other location - About 50 mins to fix
      waterbutler/core/metrics.py on lines 154..159

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          def new_subrecord(self, name):
              """Create a new MetricsSubRecord object with our category and save it to the subrecords
              list."""
              subrecord = MetricsSubRecord(self.category, name)
              self.subrecords.append(subrecord)
      Severity: Minor
      Found in waterbutler/core/metrics.py and 1 other location - About 50 mins to fix
      waterbutler/core/metrics.py on lines 177..191

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      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