eventmachine/eventmachine

View on GitHub
lib/eventmachine.rb

Summary

Maintainability
F
4 days
Test Coverage

File eventmachine.rb has 527 lines of code (exceeds 250 allowed). Consider refactoring.
Open

if defined?(EventMachine.library_type) and EventMachine.library_type == :pure_ruby
  # assume 'em/pure_ruby' was loaded already
elsif RUBY_PLATFORM =~ /java/
  require 'java'
  require 'jeventmachine'
Severity: Major
Found in lib/eventmachine.rb - About 1 day to fix

    Method event_callback has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.event_callback conn_binding, opcode, data
        #
        # Changed 27Dec07: Eliminated the hookable error handling.
        # No one was using it, and it degraded performance significantly.
        # It's in original_event_callback, which is dead code.
    Severity: Minor
    Found in lib/eventmachine.rb - 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

    Method run has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.run blk=nil, tail=nil, &block
        # Obsoleted the use_threads mechanism.
        # 25Nov06: Added the begin/ensure block. We need to be sure that release_machine
        # gets called even if an exception gets thrown within any of the user code
        # that the event loop runs. The best way to see this is to run a unit
    Severity: Minor
    Found in lib/eventmachine.rb - 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

    Method event_callback has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.event_callback conn_binding, opcode, data
        #
        # Changed 27Dec07: Eliminated the hookable error handling.
        # No one was using it, and it degraded performance significantly.
        # It's in original_event_callback, which is dead code.
    Severity: Major
    Found in lib/eventmachine.rb - About 2 hrs to fix

      Method spawn_threadpool has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.spawn_threadpool
          until @threadpool.size == @threadpool_size.to_i
            thread = Thread.new do
              Thread.current.abort_on_exception = true
              while true
      Severity: Minor
      Found in lib/eventmachine.rb - 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

      Method klass_from_handler has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.klass_from_handler(klass = Connection, handler = nil, *args)
          klass = if handler and handler.is_a?(Class)
            raise ArgumentError, "must provide module or subclass of #{klass.name}" unless klass >= handler
            handler
          elsif handler
      Severity: Minor
      Found in lib/eventmachine.rb - 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

      Method run has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.run blk=nil, tail=nil, &block
          # Obsoleted the use_threads mechanism.
          # 25Nov06: Added the begin/ensure block. We need to be sure that release_machine
          # gets called even if an exception gets thrown within any of the user code
          # that the event loop runs. The best way to see this is to run a unit
      Severity: Minor
      Found in lib/eventmachine.rb - About 1 hr to fix

        Method bind_connect has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.bind_connect bind_addr, bind_port, server, port=nil, handler=nil, *args
            begin
              port = Integer(port)
            rescue ArgumentError, TypeError
              # there was no port, so server must be a unix domain socket
        Severity: Minor
        Found in lib/eventmachine.rb - 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

        Method run_deferred_callbacks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.run_deferred_callbacks
            until (@resultqueue ||= []).empty?
              result,cback = @resultqueue.pop
              cback.call result if cback
            end
        Severity: Minor
        Found in lib/eventmachine.rb - 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

        Method bind_connect has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def self.bind_connect bind_addr, bind_port, server, port=nil, handler=nil, *args
        Severity: Minor
        Found in lib/eventmachine.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                return if t == false # timer cancelled
          Severity: Major
          Found in lib/eventmachine.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        rescue Exception => error
                          @wrapped_exception = error
                          stop
            Severity: Major
            Found in lib/eventmachine.rb - About 45 mins to fix

              Method start_server has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.start_server server, port=nil, handler=nil, *args, &block
                  begin
                    port = Integer(port)
                  rescue ArgumentError, TypeError
                    # there was no port, so server must be a unix domain socket
              Severity: Minor
              Found in lib/eventmachine.rb - 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

                  elsif opcode == ConnectionData
                    c = @conns[conn_binding] or raise ConnectionNotBound, "received data #{data} for unknown signature: #{conn_binding}"
                    c.receive_data data
                  elsif opcode == LoopbreakSignalled
                    run_deferred_callbacks
              Severity: Major
              Found in lib/eventmachine.rb - About 45 mins to fix

                Method connect has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def self.connect server, port=nil, handler=nil, *args, &blk
                Severity: Minor
                Found in lib/eventmachine.rb - About 35 mins to fix

                  Method start_server has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def self.start_server server, port=nil, handler=nil, *args, &block
                  Severity: Minor
                  Found in lib/eventmachine.rb - About 35 mins to fix

                    Method attach_io has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def EventMachine::attach_io io, watch_mode, handler=nil, *args
                        klass = klass_from_handler(Connection, handler, *args)
                    
                        if !watch_mode and klass.public_instance_methods.any?{|m| [:notify_readable, :notify_writable].include? m.to_sym }
                          raise ArgumentError, "notify_readable/writable with EM.attach is not supported. Use EM.watch(io){ |c| c.notify_readable = true }"
                    Severity: Minor
                    Found in lib/eventmachine.rb - 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 method.
                    Open

                        return true
                    Severity: Major
                    Found in lib/eventmachine.rb - About 30 mins to fix

                      Method reconnect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.reconnect server, port, handler
                          # Observe, the test for already-connected FAILS if we call a reconnect inside post_init,
                          # because we haven't set up the connection in @conns by that point.
                          # RESIST THE TEMPTATION to "fix" this problem by redefining the behavior of post_init.
                          #
                      Severity: Minor
                      Found in lib/eventmachine.rb - 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

                      There are no issues that match your filters.

                      Category
                      Status