scitran/core

View on GitHub

Showing 518 of 518 total issues

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

        for old_any_stanza in old_rule.get('any', []):
            if len(old_any_stanza) != 2:
                raise Exception('Confusing any-rule stanza ' + str(count) + ': ' + json.dumps(old_any_stanza))

            any_stanzas.append({ 'type': old_any_stanza[0], 'value': old_any_stanza[1] })
Severity: Major
Found in bin/database.py and 1 other location - About 5 hrs to fix
bin/database.py on lines 909..913

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 89.

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

        for old_all_stanza in old_rule.get('all', []):
            if len(old_all_stanza) != 2:
                raise Exception('Confusing all-rule stanza ' + str(count) + ': ' + json.dumps(old_all_stanza))

            all_stanzas.append({ 'type': old_all_stanza[0], 'value': old_all_stanza[1] })
Severity: Major
Found in bin/database.py and 1 other location - About 5 hrs to fix
bin/database.py on lines 903..907

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 89.

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 initialization_auth has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    def initialization_auth(self):
        drone_request = False
        job_context = None
        session_token = self.request.headers.get('Authorization', None)
        drone_secret = self.request.headers.get('X-SciTran-Auth', None)
Severity: Minor
Found in api/web/base.py - About 5 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 dicom_doctype.py has 378 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python

import ast
import copy
import dateutil.parser
Severity: Minor
Found in bin/dicom_doctype.py - About 5 hrs to fix

    Function exports has 123 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = function(grunt) {
        loadTasks(grunt);
        grunt.task.loadTasks('support/tasks/');
    
        grunt.task.registerTask('createBuildDir', function() {
    Severity: Major
    Found in swagger/Gruntfile.js - About 4 hrs to fix

      Function generate_request has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          def generate_request(self, gear):
              """
              Generate the job's request, save it to the class, and return it
      
              Parameters
      Severity: Minor
      Found in api/jobs/jobs.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

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

              if cid == 'site':
                  if not self.user_is_admin:
                      raise APIPermissionException('Modifying site-level rules can only be done by a site admin.')
              else:
                  project = ProjectStorage().get_container(cid, projection={'permissions': 1})
      Severity: Major
      Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
      api/jobs/handlers.py on lines 212..218
      api/jobs/handlers.py on lines 261..267

      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 83.

      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 3 locations. Consider refactoring.
      Open

              if cid == 'site':
                  if not self.user_is_admin:
                      raise APIPermissionException('Modifying site-level rules can only be done by a site admin.')
              else:
                  project = ProjectStorage().get_container(cid, projection={'permissions': 1})
      Severity: Major
      Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
      api/jobs/handlers.py on lines 212..218
      api/jobs/handlers.py on lines 289..295

      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 83.

      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 3 locations. Consider refactoring.
      Open

              if cid == 'site':
                  if not self.user_is_admin:
                      raise APIPermissionException('Adding site-level rules can only be done by a site admin.')
              else:
                  project = ProjectStorage().get_container(cid, projection={'permissions': 1})
      Severity: Major
      Found in api/jobs/handlers.py and 2 other locations - About 4 hrs to fix
      api/jobs/handlers.py on lines 261..267
      api/jobs/handlers.py on lines 289..295

      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 83.

      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 _build_month_report has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          def _build_month_report(self, base_query):
              """
              Builds a usage report for file size, session count and gear execution count
              Aggregates this information by month.
      
      
      Severity: Minor
      Found in api/handlers/reporthandler.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

      Function default_container has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

      def default_container(handler, container=None, target_parent_container=None):
          """
          This is the default permissions checker generator.
          The resulting permissions checker modifies the exec_op method by checking the user permissions
          on the container before actually executing this method.
      Severity: Minor
      Found in api/auth/containerauth.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 refererhandler.py has 355 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """
      Module defining RefererHandler and it's subclasses. RefererHandler
      generalizes the handling of documents that are not part of the container
      hierarchy, are always associated with (referencing) a parent container,
      and are stored in their own collection instead of an embedded list on the
      Severity: Minor
      Found in api/handlers/refererhandler.py - About 4 hrs to fix

        Function eval_match has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

        def eval_match(match_type, match_param, file_, container, regex=False):
            """
            Given a match entry, return if the match succeeded.
            """
        
        
        Severity: Minor
        Found in api/jobs/rules.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

        Function undelete has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
        Open

        def undelete(cont_name, cont_id, filename=None, include_parents=False, always_propagate=False):
            if cont_name not in cont_names:
                raise ValueError('Invalid cont_name "{}" (must be one of {})'.format(cont_name, cont_names_str))
            if not bson.ObjectId.is_valid(cont_id):
                raise ValueError('Invalid cont_id "{}" (must be parseable ObjectId)'.format(cont_id))
        Severity: Minor
        Found in bin/undelete.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 download.py has 345 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import bson
        import pytz
        import os.path
        import tarfile
        import datetime
        Severity: Minor
        Found in api/download.py - About 4 hrs to fix

          File jobs.py has 344 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          """
          Jobs
          """
          
          import bson
          Severity: Minor
          Found in api/jobs/jobs.py - About 4 hrs to fix

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

                if len(dcm_datetime) > 15:
                    fraction_str = dcm_datetime[15:]
                    fraction = float(dcm_datetime[15:])/10^(len(fraction_str))
                    fraction = int(fraction*1000)
                else:
            Severity: Major
            Found in bin/dicom_doctype.py and 1 other location - About 4 hrs to fix
            bin/dicom_doctype.py on lines 217..222

            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 77.

            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

                if len(dcm_time) > 7:
                    fraction_str = dcm_time[7:]
                    fraction = float(dcm_time[7:])/10^(len(fraction_str))
                    fraction = int(fraction*1000)
                else:
            Severity: Major
            Found in bin/dicom_doctype.py and 1 other location - About 4 hrs to fix
            bin/dicom_doctype.py on lines 242..247

            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 77.

            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 post has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
            Open

                def post(self):
                    """
                    Create a batch job proposal, insert as 'pending' if there are matched containers
                    """
            
            
            Severity: Minor
            Found in api/jobs/handlers.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

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

                def get_config(self, _id):
                    """Get a job's config"""
                    j = Job.get(_id)
                    c = j.config
                    if c is None:
            Severity: Minor
            Found in api/jobs/handlers.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

            Severity
            Category
            Status
            Source
            Language