Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EDM115 opened this issue Jan 18, 2024 · 3 comments
Assignees
Labels
DeepSource enhancement New feature or request help wanted Extra attention is needed Priority S

Comments

@EDM115
Copy link
Owner

EDM115 commented Jan 18, 2024

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 EDM115 added enhancement New feature or request DeepSource labels Jan 18, 2024
@EDM115 EDM115 self-assigned this Jan 18, 2024
@EDM115

This comment was marked as outdated.

@EDM115
Copy link
Owner Author

EDM115 commented Jan 18, 2024

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
Copy link
Owner Author

EDM115 commented Feb 12, 2024

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:

  • Break the function into smaller, more manageable functions.
  • Refactor complex logic into separate functions or classes.
  • Avoid multiple return paths and deeply nested control expressions.
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

  • unzipper/modules/commands.py
    add_vip has a cyclomatic complexity of 16 with "high" risk
  • unzipper/modules/ext_script/metadata_helper.py
    get_audio_metadata has a cyclomatic complexity of 20 with "high" risk
  • unzipper/modules/ext_script/up_helper.py
    send_file has a cyclomatic complexity of 27 with "very-high" risk
  • unzipper/modules/callbacks.py
    unzipper_cb has a cyclomatic complexity of 169 with "critical" risk

@EDM115 EDM115 added the help wanted Extra attention is needed label Feb 12, 2024
@EDM115 EDM115 changed the title (PY-R1000) Function with cyclomatic complexity higher than threshold [CRITICAL] (PY-R1000) Function with cyclomatic complexity higher than threshold Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DeepSource enhancement New feature or request help wanted Extra attention is needed Priority S
Projects
None yet
Development

No branches or pull requests

1 participant