thenetcircle/dino

View on GitHub

Showing 809 of 809 total issues

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

api_channel_actions = [(a, a.upper()) for a in acl_config[ApiTargets.CHANNEL].keys()]
Severity: Minor
Found in dino/admin/forms/__init__.py and 1 other location - About 30 mins to fix
dino/admin/forms/__init__.py on lines 27..27

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

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

Avoid too many return statements within this function.
Open

            return False
Severity: Major
Found in dino/endpoint/queue.py - About 30 mins to fix

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

            if database is not None and database != '':
                params['database'] = database
    Severity: Major
    Found in dino/db/rdbms/dbman.py and 4 other locations - About 30 mins to fix
    dino/db/rdbms/dbman.py on lines 59..60
    dino/db/rdbms/dbman.py on lines 61..62
    dino/db/rdbms/dbman.py on lines 63..64
    dino/db/rdbms/dbman.py on lines 65..66

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

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

        def add_acls_in_channel_for_action(self, channel_id: str, action: str, acls: dict) -> None:
            if not self.channel_exists(channel_id):
                raise NoSuchChannelException(channel_id)
    
            if action not in ApiActions.all_api_actions:
    Severity: Minor
    Found in dino/db/redis.py - About 25 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 add_acls_in_room_for_action has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_acls_in_room_for_action(self, room_id: str, action: str, acls: dict) -> None:
            if self.channel_for_room(room_id) is None:
                raise NoSuchRoomException(room_id)
    
            if action not in ApiActions.all_api_actions:
    Severity: Minor
    Found in dino/db/redis.py - About 25 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 publish_startup_done_event has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def publish_startup_done_event() -> None:
            if len(environ.env.config) == 0 or environ.env.config.get(ConfigKeys.TESTING, False):
                # assume we're testing
                return
    
    
    Severity: Minor
    Found in dino/hooks/startup.py - About 25 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 ban_user has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def ban_user():
        form = request.get_json()
        target = form['target']
        target_uuid = form['target_uuid']
        user_uuid = form['user_uuid']
    Severity: Minor
    Found in dino/admin/routes.py - About 25 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 enrich has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def enrich(extra: dict) -> dict:
            if 'id' in extra:
                ActivityBuilder.warn_field('id', extra)
            else:
                extra['id'] = str(uuid())
    Severity: Minor
    Found in dino/utils/activity_helper.py - About 25 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 filter_channels_by_acl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def filter_channels_by_acl(activity, channels_with_acls, session_to_use=None):
        filtered_channels = list()
    
        for channel_info in channels_with_acls:
            channel_id = channel_info['id']
    Severity: Minor
    Found in dino/utils/__init__.py - About 25 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 _get_users_with_role has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _get_users_with_role(self, roles: dict, role_key: str):
            if roles is None or len(roles) == 0:
                return dict()
    
            cleaned = dict()
    Severity: Minor
    Found in dino/db/redis.py - About 25 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 user_is_allowed_to_delete_message has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    def user_is_allowed_to_delete_message(room_id: str, user_id: str) -> bool:
        channel_id = get_channel_for_room(room_id)
        if is_owner(room_id, user_id):
            return True
        if is_moderator(room_id, user_id):
    Severity: Minor
    Found in dino/utils/__init__.py - About 25 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 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def validate(self, hosts, replications, strategy):
            if environ.env.config.get(ConfigKeys.TESTING, False):
                return
    
            if not isinstance(replications, int):
    Severity: Minor
    Found in dino/storage/cassandra.py - About 25 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 on_kick has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def on_kick(self, activity: Activity) -> (bool, int, str):
            kicker_id = activity.actor.id
            room_id = activity.target.id
            user_id_to_kick = activity.object.id
    
    
    Severity: Minor
    Found in dino/validation/request.py - About 25 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 save_spam_prediction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def save_spam_prediction(self, activity: Activity, message, y_hats: tuple, session=None):
            to_name = activity.target.display_name
            from_name = activity.actor.display_name
    
            if is_base64(to_name):
    Severity: Minor
    Found in dino/db/rdbms/handler.py - About 25 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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, env, is_external_queue: bool):
            super().__init__(env, is_external_queue, queue_type='amqp', logger=logger)
            conf = env.config
    
            queue_host = conf.get(ConfigKeys.HOST, domain=self.domain_key, default='')
    Severity: Minor
    Found in dino/endpoint/amqp.py - About 25 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 mute_user has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def mute_user(self, user_id: str, mute_info: dict):
            duration = mute_info.get('duration', '')
            reason = mute_info.get('reason', '')
            muter_id = mute_info.get('muter_user_id', '')
            room_name = mute_info.get('room_name', '')
    Severity: Minor
    Found in dino/rest/resources/mute.py - About 25 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 cleanup has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def cleanup(self):
            """
            avoid in-memory cache buildup, since keys are only deleted if
            the expiry time has passed when accessing them
            """
    Severity: Minor
    Found in dino/cache/redis.py - About 25 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 get_room_id_for_name has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_room_id_for_name(self, room_name: str, use_default_channel: bool = False) -> str:
            @with_session
            def _do_get(session=None):
                return session.query(Rooms)\
                    .filter(Rooms.name == room_name)\
    Severity: Minor
    Found in dino/db/rdbms/handler.py - About 25 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 get_user_for_sid has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_user_for_sid(self, sid: str) -> str:
            @with_session
            def _get_user_for_sid(session=None):
                sid_entity = session.query(Sids).filter(Sids.sid == sid).first()
                if sid_entity is None:
    Severity: Minor
    Found in dino/db/rdbms/handler.py - About 25 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 is_banned_globally has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def is_banned_globally(self, user_id: str) -> (bool, Union[str, None]):
            now = datetime.utcnow()
            duration, time, username = self.env.cache.get_global_ban_timestamp(user_id)
            if time is not None and len(time.strip()) != 0:
                time = datetime.fromtimestamp(float(time))
    Severity: Minor
    Found in dino/db/rdbms/handler.py - About 25 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