Showing 118 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

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

Severity: Major
Found in slim/utils/ref.py and 1 other location - About 1 day to fix
slim/utils/proxy.py on lines 0..23

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

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

Severity: Major
Found in slim/utils/proxy.py and 1 other location - About 1 day to fix
slim/utils/ref.py on lines 0..23

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

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

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

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

            def signin(self, username, password):
                resp = self.do_request('POST', '/signin', post_data={'username': username, 'password': password}, role=None)
                assert resp['code'] == 0, resp
                config['request']['access_token'] = resp['data']['access_token']
                return resp
        Severity: Major
        Found in slim_cli/template/tools/request.py and 1 other location - About 4 hrs to fix
        slim_cli/template/tools/request.py on lines 30..34

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

        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 signup(self, username, password):
                resp = self.do_request('POST', '/signup', post_data={'username': username, 'password': password}, role=None)
                assert resp['code'] == 0, resp
                config['request']['access_token'] = resp['data']['access_token']
                return resp
        Severity: Major
        Found in slim_cli/template/tools/request.py and 1 other location - About 4 hrs to fix
        slim_cli/template/tools/request.py on lines 24..28

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

        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

        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

              Severity
              Category
              Status
              Source
              Language