EDM115 / unzip-bot

Telegram bot deployable to heroku that can extract every archive !
https://t.me/unzip_edm115bot
MIT License
91 stars 125 forks source link

[CRITICAL] (PY-R1000) Function with cyclomatic complexity higher than threshold #267

Open EDM115 opened 7 months ago

EDM115 commented 7 months ago

Description

A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.

Occurrences

There are 3 occurrences of this issue in the repository.

See all occurrences on DeepSource → app.deepsource.com/gh/EDM115/unzip-bot/issue/PY-R1000/occurrences/

EDM115 commented 7 months ago

https://chat.openai.com/share/e6166e61-bfca-44e1-8c24-065b6df09b2e

EDM115 commented 7 months ago

related to #159 :

from mutagen.easyid3 import EasyID3
from mutagen.mp3 import MP3

# ... [Your existing code] ...

async def send_file(unzip_bot, c_id, doc_f, query, full_path, log_msg, split):
    # ... [Your existing code] ...
    try:
        # ... [Your existing code] ...

        # Attempt to extract audio metadata
        audio_meta = {}
        try:
            audio = MP3(doc_f, ID3=EasyID3)
            audio_meta['duration'] = int(audio.info.length)  # Duration in seconds
            audio_meta['performer'] = audio.get('artist', [None])[0]  # Performer name
            audio_meta['title'] = audio.get('title', [None])[0]  # Track name
        except Exception as e:
            LOGGER.error(f"Error extracting metadata: {e}")

        # ... [Your existing code for upmsg and thumbornot] ...

        if ul_mode == "media" and fext in extentions_list["audio"]:
            send_kwargs = {
                'chat_id': c_id,
                'audio': doc_f,
                'caption': Messages.EXT_CAPTION.format(fname),
                'disable_notification': True,
                'progress': progress_for_pyrogram,
                'progress_args': (
                    Messages.TRY_UP.format(fname),
                    upmsg,
                    time(),
                    unzip_bot,
                ),
                'duration': audio_meta.get('duration'),
                'performer': audio_meta.get('performer'),
                'title': audio_meta.get('title'),
            }

            if thumbornot:
                send_kwargs['thumb'] = Config.THUMB_LOCATION + "/" + str(c_id) + ".jpg"

            await unzip_bot.send_audio(**send_kwargs)

    # ... [Your existing code] ...

using kwargs might not be a bad idea

EDM115 commented 6 months ago

DESCRIPTION
A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.
Functions with high cyclomatic complexity are more likely to have bugs and be harder to test. They may lead to reduced code maintainability and increased development time.
To reduce the cyclomatic complexity of a function, you can:

Risk category Cyclomatic complexity range Recommended action
low 1-5 No action needed.
medium 6-15 Review and monitor.
high 16-25 Review and refactor. Recommended to add comments if the function is absolutely needed to be kept as it is.
very-high 26-50 Refactor to reduce the complexity.
critical >50 Must refactor this. This can make the code untestable and very difficult to understand.

Occurrences