vladcalin/gemstone

View on GitHub

Showing 29 of 29 total issues

File microservice.py has 331 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import os
import functools
import random
import threading
Severity: Minor
Found in gemstone/core/microservice.py - About 3 hrs to fix

    MicroService has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MicroService(Container):
        #: The name of the service. Is required.
        name = None
    
        #: The host where the service will listen
    Severity: Minor
    Found in gemstone/core/microservice.py - About 3 hrs to fix

      Function post has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

          def post(self):
              if self.request.headers.get("Content-type").split(";")[0] != "application/json":
                  self.write_single_response(GenericResponse.INVALID_REQUEST)
                  return
      
      
      Severity: Minor
      Found in gemstone/core/handlers.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 handle_single_request has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def handle_single_request(self, request_object):
              """
              Handles a single request object and returns the correct result as follows:
      
              - A valid response object if it is a regular request (with ID)
      Severity: Minor
      Found in gemstone/core/handlers.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 parse_json_structure has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def parse_json_structure(string_item):
          """
          Given a raw representation of a json structure, returns the parsed corresponding data
          structure (``JsonRpcRequest`` or ``JsonRpcRequestBatch``)
      
      
      Severity: Minor
      Found in gemstone/core/structs.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 exposed_method has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def exposed_method(name=None, private=False, is_coroutine=True, requires_handler_reference=False):
          """
          Marks a method as exposed via JSON RPC.
      
          :param name: the name of the exposed method. Must contains only letters, digits, dots and underscores.
      Severity: Minor
      Found in gemstone/core/decorators.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 get_service has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_service(self, name):
              """
              Locates a remote service by name. The name can be a glob-like pattern
              (``"project.worker.*"``). If multiple services match the given name, a
              random instance will be chosen. There might be multiple services that
      Severity: Minor
      Found in gemstone/core/microservice.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 from_dict has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def from_dict(cls, d):
              """
              Validates a dict instance and transforms it in a
              :py:class:`gemstone.core.structs.JsonRpcRequest`
              instance
      Severity: Minor
      Found in gemstone/core/structs.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

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

          def _gather_event_handlers(self):
              """
              Searches for the event handlers in the current microservice class.
      
              :return:
      Severity: Minor
      Found in gemstone/core/microservice.py and 1 other location - About 45 mins to fix
      gemstone/core/microservice.py on lines 404..414

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

      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 _gather_exposed_methods(self):
              """
              Searches for the exposed methods in the current microservice class. A method is considered
              exposed if it is decorated with the :py:func:`gemstone.public_method` or
              :py:func:`gemstone.private_api_method`.
      Severity: Minor
      Found in gemstone/core/microservice.py and 1 other location - About 45 mins to fix
      gemstone/core/microservice.py on lines 424..432

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

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

      def as_completed(*async_result_wrappers):
          """
          Yields results as they become available from asynchronous method calls.
      
          Example usage
      Severity: Minor
      Found in gemstone/util.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

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

          @gemstone.exposed_method()
          def broadcast_msg(self, message):
              self.emit_event("test", {"msg": message}, broadcast=True)
              return True
      Severity: Minor
      Found in examples/example_publisher_subscriber/producer.py and 1 other location - About 40 mins to fix
      examples/example_publisher_subscriber/producer.py on lines 19..22

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

      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

          @gemstone.exposed_method()
          def single_msg(self, message):
              self.emit_event("test", {"msg": message}, broadcast=False)
              return True
      Severity: Minor
      Found in examples/example_publisher_subscriber/producer.py and 1 other location - About 40 mins to fix
      examples/example_publisher_subscriber/producer.py on lines 14..17

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

      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 __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, host="127.0.0.1", port=5672, username="", password="", **connection_options):
      Severity: Minor
      Found in gemstone/event/transport/rabbitmq.py - About 35 mins to fix

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

            def _activate_configurators(self):
                for configurator in self.configurators:
                    configurator.load()
        
                for configurator in self.configurators:
        Severity: Minor
        Found in gemstone/core/microservice.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 prepare_method_call has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def prepare_method_call(self, method, args):
                """
                Wraps a method so that method() will call ``method(*args)`` or ``method(**args)``,
                depending of args type
        
        
        Severity: Minor
        Found in gemstone/core/handlers.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 call_batch has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def call_batch(self, *requests):
                body = []
                ids = {}
                for item in requests:
                    if not isinstance(item, (MethodCall, Notification)):
        Severity: Minor
        Found in gemstone/client/remote_service.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 expire_entries has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def expire_entries(self):
                with self.container_lock:
                    for _, entries in self.container.items():
                        i = 0
                        while i < len(entries):
        Severity: Minor
        Found in gemstone/discovery/cache.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

        Avoid too many return statements within this function.
        Open

                    return err
        Severity: Major
        Found in gemstone/core/handlers.py - About 30 mins to fix

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

              for item in async_result_wrappers:
                  if not isinstance(item, AsyncMethodCall):
                      raise TypeError("Got non-AsyncMethodCall object: {}".format(item))
          Severity: Minor
          Found in gemstone/util.py and 1 other location - About 30 mins to fix
          gemstone/util.py on lines 58..60

          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

          Severity
          Category
          Status
          Source
          Language