Showing 110 of 118 total issues

Function _build_paths has a Cognitive Complexity of 122 (exceeds 5 allowed). Consider refactoring.
Open

    def _build_paths(self):
        from slim.base.view import BaseView, AbstractSQLView
        paths = {}

        def returning_wrap(items_schema):
Severity: Minor
Found in slim/ext/openapi/main.py - About 2 days 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 bind has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
Open

    def bind(self, view: "AbstractSQLView"):
        def check_column_exists(column):
            if column is PRIMARY_KEY:
                return
            if column not in view.fields:
Severity: Minor
Found in slim/base/sqlquery.py - About 1 day 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 sqlquery.py has 568 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import logging
import traceback
from enum import Enum
from typing import Union, Iterable, List, TYPE_CHECKING, Dict, Set, Mapping
Severity: Major
Found in slim/base/sqlquery.py - About 1 day to fix

    Function tokens_to_template has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    def tokens_to_template(tokens):
        """
        Generate a function for templating tokens into a path string.
        """
        def template_function(obj):
    Severity: Minor
    Found in slim/utils/repath.py - About 7 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 abstract_sql_view.py has 451 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import json
    import logging
    from abc import abstractmethod
    from typing import Tuple, Union, Dict, Iterable, Type, List, Optional, Mapping
    
    
    Severity: Minor
    Found in slim/base/_view/abstract_sql_view.py - About 6 hrs to fix

      Function get_cooldown_decorator has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_cooldown_decorator(aioredis_instance: object, default_unique_id_func=get_ip) -> object:
          redis = aioredis_instance
      
          def cooldown(interval_value_or_func, redis_key_template, *, unique_id_func=default_unique_id_func, cd_if_unsuccessed=None):
              def wrapper(func):
      Severity: Minor
      Found in slim/ext/decorator.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 main.py has 395 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
      from copy import deepcopy
      from typing import Type, TYPE_CHECKING
      
      from slim.base.types import BuiltinInterface
      Severity: Minor
      Found in slim/ext/openapi/main.py - About 5 hrs to fix

        Function check_query_permission_full has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_query_permission_full(self, user: "BaseUser", table: str, ability: "Ability", view: "AbstractSQLView", ignore_error=True):
                from .permission import A
        
                # QUERY 权限检查
                # QUERY 的特殊之处在于即使没有查询条件也会查出数据
        Severity: Minor
        Found in slim/base/sqlquery.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

        Function _bind has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
        Open

            def _bind(self):
                from ._view.request_view import RequestView
                from ._view.abstract_sql_view import AbstractSQLView
        
                def add_to_url_mapping(_meta, _fullpath):
        Severity: Minor
        Found in slim/base/route.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

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

            def __exit__(self, exc_type, exc_val: Exception, exc_tb):
                # FinishQuitException
                if isinstance(exc_val, FinishQuitException):
                    return True  # Finished, do nothing
        
        
        Severity: Minor
        Found in slim/base/_view/err_catch_context.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 base_view.py has 347 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import asyncio
        import json
        import logging
        import time
        from collections import OrderedDict
        Severity: Minor
        Found in slim/base/_view/base_view.py - About 4 hrs to fix

          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

          Function createAPIRequester has 106 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function createAPIRequester (ctx) {
              function getAccessToken () {
                  if (!ctx) {
                      return localStorage.getItem('t')
                  }
          Severity: Major
          Found in slim_cli/template/tools/netapi.js - About 4 hrs to fix

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

                  def parse_load_fk(cls, data: Dict[str, List[Dict[str, object]]]) -> Dict[str, List[Dict[str, object]]]:
                      """
                      :param data:{
                          <column>: role,
                          <column2>: role,
              Severity: Minor
              Found in slim/base/sqlquery.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 createAPIRequester has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
              Open

              export function createAPIRequester (ctx) {
                  function getAccessToken () {
                      if (!ctx) {
                          return localStorage.getItem('t')
                      }
              Severity: Minor
              Found in slim_cli/template/tools/netapi.js - 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

              Function _parse_permission_value has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _parse_permission_value(self, val) -> Set[str]:
                      """
                      从 obj 中取出权限列表
                      :param val:
                      :return: {A.QUERY, A.WRITE, ...}
              Severity: Minor
              Found in slim/base/permission.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

              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

              Function import_path has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
              Open

              def import_path(path, depth=-1):
                  if depth == 0:
                      return
              
                  for base_path in sys.path:
              Severity: Minor
              Found in slim/utils/autoload.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 query_path has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
              Open

                  def query_path(self, method, path) -> Tuple[Union[RouteInterfaceInfo, RouteStaticsInfo, None], Optional[Dict]]:
                      """
                      Get route info for specified method and path.
                      :param method:
                      :param path:
              Severity: Minor
              Found in slim/base/route.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

              Severity
              Category
              Status
              Source
              Language