thumbor/thumbor

View on GitHub

Showing 64 of 69 total issues

Function _load_results has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def _load_results(self, context):
        image_extension, content_type = self.define_image_type(context, None)

        quality = self.context.request.quality

Severity: Minor
Found in thumbor/handlers/__init__.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_mimetype has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def get_mimetype(cls, buffer):
        img_mime = None

        if buffer.startswith(b"GIF8"):
            img_mime = "image/gif"
Severity: Minor
Found in thumbor/engines/__init__.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 return_contents has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def return_contents(response, url, context, req_start=None):
    res = urlparse(url)
    netloc = res.netloc.replace(".", "_")
    code = response.code

Severity: Minor
Found in thumbor/loaders/http_loader.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 __init__ has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def __init__(
        self,
        debug=False,
        meta=False,
        trim=None,
Severity: Minor
Found in thumbor/context.py - About 1 hr to fix

    Function fit_in_resize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def fit_in_resize(self):
            source_width, source_height = self.engine.size
    
            # invert width and height if image orientation is not the
            # same as request orientation and need adaptive
    Severity: Minor
    Found in thumbor/transformer.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 handle_error has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_error(self, context, handler, exception):
            # create log file if not existing
            if not self.logger:
                if self.use_context:
                    obj = operator.attrgetter(self.use_context)(context)
    Severity: Minor
    Found in thumbor/error_handlers/file.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 translate_crop_coordinates has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def translate_crop_coordinates(
    Severity: Major
    Found in thumbor/handlers/__init__.py - About 1 hr to fix

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

          def parse_url(self, url):
              level = 0
              while level < MAX_LEVEL:
                  url = self.domain_regex.sub("", url)
                  result = self.url_regex.match(url)
      Severity: Minor
      Found in thumbor/filters/extract_focal.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 on_finish has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def on_finish(self):
              super().on_finish()
              self.context = getattr(self, "context", None)
      
              if self.context is None:
      Severity: Minor
      Found in thumbor/handlers/__init__.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_thumbor_params has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_thumbor_params(image_url, params, config):
          if params.key_file:
              with open(params.key_file, "rb") as key_file:
                  security_key = key_file.read().strip()
          else:
      Severity: Minor
      Found in thumbor/url_composer.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 img_operation_worker has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def img_operation_worker(self):
              if (
                  self.context.request.engine.extension == ".gif"
                  and "cover()" in self.context.request.filters
              ):
      Severity: Minor
      Found in thumbor/transformer.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 ensure_srgb has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def ensure_srgb(img, srgb_profile=None):
          """
          Ensures that an image either has no ICC profile (and so is implicitly
          sRGB) or has an sRGB color profile. If the image is sRGB, it is returned
          unchanged. If it has a CMYK or Gray color profile, this function will
      Severity: Minor
      Found in thumbor/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 get_detection_offset has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_detection_offset(
      Severity: Major
      Found in thumbor/detectors/local_detector.py - About 1 hr to fix

        Function __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(
        Severity: Major
        Found in thumbor/point.py - About 1 hr to fix

          Function __init__ has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def __init__(
                  self, server=None, config=None, importer=None, request_handler=None
              ):
                  self.server = server
                  self.config = config
          Severity: Minor
          Found in thumbor/context.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_image has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_image(self, buffer):
                  try:
                      img = Image.open(BytesIO(buffer))
                  except DECOMPRESSION_BOMB_EXCEPTIONS as error:
                      logger.warning("[PILEngine] create_image failed: %s", error)
          Severity: Minor
          Found in thumbor/engines/pil.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 run_optimizer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def run_optimizer(self, image_extension, buffer):
                  if not self.should_run(image_extension, buffer):
                      return buffer
          
                  if "strip_icc" in self.context.request.filters:
          Severity: Minor
          Found in thumbor/optimizers/jpegtran.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_instances has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def create_instances(self, context, filter_params):
                  filter_instances = collections.defaultdict(list)
                  if not filter_params:
                      return FiltersRunner(filter_instances)
          
          
          Severity: Minor
          Found in thumbor/filters/__init__.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 validate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def validate(context, url, normalize_url_func=_normalize_url):
              url = normalize_url_func(url)
              res = urlparse(url)
          
              if not res.hostname:
          Severity: Minor
          Found in thumbor/loaders/http_loader.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 compile_regex has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def compile_regex(cls, filter_data):
                  params = filter_data["params"]
                  defaults = filter_data.get("defaults", None)
                  regexes = []
                  parsers = []
          Severity: Minor
          Found in thumbor/filters/__init__.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