iranzo/stampython

View on GitHub
stampy/stampy.py

Summary

Maintainability
F
6 days
Test Coverage

File stampy.py has 793 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# encoding: utf-8
#
# Description: Bot for controlling karma on Telegram
# Author: Pablo Iranzo Gomez (Pablo.Iranzo@gmail.com)
Severity: Major
Found in stampy/stampy.py - About 1 day to fix

    Function sendmessage has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
    Open

    def sendmessage(chat_id=0, text="", reply_to_message_id=False,
                    disable_web_page_preview=True, parse_mode=False,
                    extra=False):
        """
        Sends a message to a chat
    Severity: Minor
    Found in stampy/stampy.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

    Function process has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def process(messages):
        """
        This function processes the updates in the Updates URL at Telegram
        for finding commands, karma changes, config, etc
        """
    Severity: Minor
    Found in stampy/stampy.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 deletemessage has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def deletemessage(chat_id=0, message_id=False):
        """
        Deletes a message from a chat
        :param chat_id: chat_id to delete the message
        :param message_id: message to delete
    Severity: Minor
    Found in stampy/stampy.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 getmsgdetail has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def getmsgdetail(message):
        """
        Gets message details and returns them as dict
        :param message: message to get details from
        :return: message details as dict
    Severity: Minor
    Found in stampy/stampy.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 is_owner_or_admin has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def is_owner_or_admin(message, strict=False):
        """
        Check if user is owner or admin for group
        :param strict: Defines if we target the actual gid, not effective
        :param message: message to check
    Severity: Minor
    Found in stampy/stampy.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 main has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
        """
        Main code for the bot
        """
    
    
    Severity: Minor
    Found in stampy/stampy.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 loglevel has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def loglevel():
        """
        This functions stores or sets the proper log level based on the
        database configuration
        """
    Severity: Minor
    Found in stampy/stampy.py - About 1 hr 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 dbsql has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def dbsql(sql=False):
        """
        Performs SQL operation on database
        :param sql: sql command to execute
        :return:
    Severity: Minor
    Found in stampy/stampy.py - About 1 hr 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 shouldrun has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def shouldrun(name):
        """
        Checks name on database to see if it should run or not and updates as executed
        :param name: Name to check on database
        :return: Bool
    Severity: Minor
    Found in stampy/stampy.py - About 55 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 getitems has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def getitems(var):
        """
        Returns list of items even if provided args are lists of lists
        :param var: list or value to pass
        :return: unique list of values
    Severity: Minor
    Found in stampy/stampy.py - About 55 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 sendmessage has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def sendmessage(chat_id=0, text="", reply_to_message_id=False,
    Severity: Minor
    Found in stampy/stampy.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if command == trigger[1:]:
                              runplugin = True
                              break
                      elif trigger in texto:
      Severity: Major
      Found in stampy/stampy.py - About 45 mins to fix

        Function sendimage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def sendimage(chat_id=0, image="", text="", reply_to_message_id=""):
            """
            Sends an image to chat_id as a reply to a message received
            :param chat_id: ID of the chat
            :param image: image URI
        Severity: Minor
        Found in stampy/stampy.py - About 45 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

        Error: invalid syntax (<unknown>, line 139)</unknown>
        Open

            except lite.Error, e:
        Severity: Minor
        Found in stampy/stampy.py by radon

        We encountered an error attempting to analyze this line.

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

                if UTdisable and Silent:
                    result = json.load(urllib.urlopen(message))
                    code = result['ok']
                else:
                    code = True
        Severity: Major
        Found in stampy/stampy.py and 1 other location - About 1 hr to fix
        stampy/stampy.py on lines 332..337

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

        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

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

                if UTdisable and Silent:
                    result = json.load(urllib.urlopen(message))
                    code = result['ok']
                else:
                    code = True
        Severity: Major
        Found in stampy/stampy.py and 1 other location - About 1 hr to fix
        stampy/stampy.py on lines 241..246

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

        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

        There are no issues that match your filters.

        Category
        Status