mrDoctorWho/vk4xmpp

View on GitHub
gateway.py

Summary

Maintainability
F
6 days
Test Coverage

File gateway.py has 1112 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python2
# coding: utf-8

# vk4xmpp gateway, v3.6
# © simpleApps, 2013 — 2018.
Severity: Major
Found in gateway.py - About 2 days to fix

    Function sendMessages has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def sendMessages(self, init=False, messages=None, mid=0, uid=0, filter_="unread"):
            """
            Sends messages from vk to xmpp and call message01 handlers
            Args:
                init: needed to know if function called at init (add time or not)
    Severity: Minor
    Found in gateway.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 method has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        def method(self, method, args=None, force=False, notoken=False):
            """
            This is a duplicate function of self.engine.method
            Needed to handle errors properly exactly in __main__
            Args:
    Severity: Minor
    Found in gateway.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

    VK has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class VK(object):
        """
        Contains methods to handle the VK stuff
        """
        def __init__(self, token=None, source=None):
    Severity: Minor
    Found in gateway.py - About 2 hrs to fix

      Function updateFriends has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def updateFriends(self, cTime):
              """
              Updates friends list.
              Compares the current friends list to the new list
              Takes a corresponding action if any difference found
      Severity: Minor
      Found in gateway.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 getMessagesBulk has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def getMessagesBulk(self, peers, count=20, mid=0):
              """
              Receives messages for all the conversations' peers
              25 is the maximum number of conversations we can receive in a single request
              The sky is the limit!
      Severity: Minor
      Found in gateway.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 checkPID has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      def checkPID():
          """
          Gets a new PID and kills the previous PID
          by signal 15 and then by 9
          """
      Severity: Minor
      Found in gateway.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 removeUser has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def removeUser(user, roster=False, notify=True):
          """
          Removes user from the database
          Args:
              user: User class object or jid without resource
      Severity: Minor
      Found in gateway.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 connect has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def connect(self, username=None, password=None, token=None):
              """
              Initializes a VK() object and tries to make an authorization if no token provided
              Args:
                  username: the user's phone number or e-mail for password authentication
      Severity: Minor
      Found in gateway.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 sendMessage has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def sendMessage(destination, source, body=None, timestamp=0, typ="active", mtype="chat", mid=0):
      Severity: Major
      Found in gateway.py - About 50 mins to fix

        Function sendPresence has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def sendPresence(destination, source, pType=None, nick=None,
        Severity: Major
        Found in gateway.py - About 50 mins to fix

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

              def sendInitPresence(self):
                  """
                  Sends available presence to the user from all online friends
                  """
                  if not self.vk.engine.captcha:
          Severity: Minor
          Found in gateway.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

          Avoid deeply nested control flow statements.
          Open

                                  if not item:
                                      continue
                                  messages.extend(item)
          Severity: Major
          Found in gateway.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if self.settings.force_vk_date or init:
                                        date = message["date"]
                                    self.lastMsgByUser[frm] = mid
            Severity: Major
            Found in gateway.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if status == MSG_SKIP:
                                          for func in iter_:
                                              utils.execute(func, (self, message))
                                          break
                                      elif status == MSG_APPEND:
              Severity: Major
              Found in gateway.py - About 45 mins to fix

                Function sendMessages has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def sendMessages(self, init=False, messages=None, mid=0, uid=0, filter_="unread"):
                Severity: Minor
                Found in gateway.py - About 35 mins to fix

                  Function sendMessage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      def sendMessage(self, body, id, mType="user_id", more={}, mid=0):
                  Severity: Minor
                  Found in gateway.py - About 35 mins to fix

                    Function getPeerIds has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def getPeerIds(conversations, source=None):
                            """
                            Returns a list of peer ids that exist in the given conversations
                            Args:
                                conversations: list of Conversations objects
                    Severity: Minor
                    Found in gateway.py - About 35 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 getUserData has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def getUserData(self, uid, fields=None):
                            """
                            Gets user data. Such as name, photo, etc
                            Args:
                                uid: the user id (list or str)
                    Severity: Minor
                    Found in gateway.py - About 35 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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def initialize(self, force=False, send=True, resource=None, first=False):
                            """
                            Initializes user after the connection has been completed
                            Args:
                                force: force sending subscription presence
                    Severity: Minor
                    Found in gateway.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

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

                        def getPermissions(self):
                            """
                            Update the app permissions
                            Returns:
                                The current permission mask
                    Severity: Minor
                    Found in gateway.py and 1 other location - About 55 mins to fix
                    gateway.py on lines 570..578

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

                    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 getLists(self):
                            """
                            Receive the list of the user friends' groups
                            Returns:
                                a list of user friends groups
                    Severity: Minor
                    Found in gateway.py and 1 other location - About 55 mins to fix
                    gateway.py on lines 560..568

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

                    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