slim/base/web.py

Summary

Maintainability
D
1 day
Test Coverage

Function build_headers has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    def build_headers(self):
        headers = [
            # TODO: bytes convert cache
            [const.CONTENT_TYPE.encode('utf-8'), self.content_type.encode('utf-8')]
         ]
Severity: Minor
Found in slim/base/web.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 web.py has 343 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import asyncio
import hashlib
import logging
import os
import time
Severity: Minor
Found in slim/base/web.py - About 4 hrs to fix

    Function pack_headers has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def pack_headers(self, request: 'ASGIRequest'):
            def solve(val):
                if isinstance(val, str):
                    return val
                elif isinstance(val, Iterable):
    Severity: Minor
    Found in slim/base/web.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

    Avoid deeply nested control flow statements.
    Open

                            if route_info.names_varkw is not None:
                                for j in route_info.names_exclude:
                                    if j in call_kwargs:
                                        del call_kwargs[j]
    
    
    Severity: Major
    Found in slim/base/web.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if isinstance(view, AbstractSQLView):
                                  view.current_interface = route_info.builtin_interface
      
                              # make the method bounded
                              handler = route_info.handler.__get__(view)
      Severity: Major
      Found in slim/base/web.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if not view.is_finished:
                                    # user's validator check
                                    await view_validate_check(view, route_info.va_query, route_info.va_post, route_info.va_headers)
        
                                    ret_resp = None
        Severity: Major
        Found in slim/base/web.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for j in call_kwargs.keys() - route_info.names_include:
                                      del call_kwargs[j]
          
                                  # build a view instance
                                  view = await route_info.view_cls._build(app, request)
          Severity: Major
          Found in slim/base/web.py - About 45 mins to fix

            There are no issues that match your filters.

            Category
            Status