eventmachine/eventmachine

View on GitHub

Showing 147 of 147 total issues

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

  def handle_direct_message(input)
    username, message = parse_direct_message(input)

    if connection = @@connected_clients.find { |c| c.username == username }
      puts "[dm] @#{@username} => @#{username}"
Severity: Minor
Found in examples/guides/getting_started/03_simple_chat_server.rb and 1 other location - About 55 mins to fix
examples/guides/getting_started/08_simple_chat_server_step_five.rb on lines 86..93

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

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 CONFIG['CC'] == 'cc' && (
     `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
     `cc -V 2>&1` =~ /Sun/        # detect Solaris Studio compiler
    )
    # SUN CHAIN
Severity: Minor
Found in ext/extconf.rb and 1 other location - About 45 mins to fix
ext/fastfilereader/extconf.rb on lines 65..80

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

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 CONFIG['CC'] == 'cc' && (
     `cc -flags 2>&1` =~ /Sun/ || # detect SUNWspro compiler
     `cc -V 2>&1` =~ /Sun/        # detect Solaris Studio compiler
    )
    # SUN CHAIN
Severity: Minor
Found in ext/fastfilereader/extconf.rb and 1 other location - About 45 mins to fix
ext/extconf.rb on lines 185..200

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

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

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

    public ByteBuffer dispatchInboundData (ByteBuffer bb) throws SSLException {
        if (sslEngine != null) {
            if (true) throw new RuntimeException ("TLS currently unimplemented");
            System.setProperty("javax.net.debug", "all");
            ByteBuffer w = ByteBuffer.allocate(32*1024); // TODO, WRONG, preallocate this buffer.
Severity: Minor
Found in java/src/com/rubyeventmachine/EventableSocketChannel.java - 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 isReadable has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    void isReadable (SelectionKey k) {
        EventableChannel ec = (EventableChannel) k.attachment();
        long b = ec.getBinding();

        if (ec.isWatchOnly()) {
Severity: Minor
Found in java/src/com/rubyeventmachine/EmReactor.java - 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

  add_define 'WITH_SSL' if find_openssl_library
Severity: Major
Found in ext/extconf.rb - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

    elsif find_openssl_library
      # If we don't even need any options to find a usable OpenSSL, go with it
      add_define 'WITH_SSL'
    elsif dir_config_search('OpenSSL', 'openssl', ['/usr/local', '/opt/local', '/usr/local/opt/openssl']) do
        find_openssl_library
    Severity: Major
    Found in ext/extconf.rb - About 45 mins to fix

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

          public void close() {
              if (channelKey != null) {
                  channelKey.cancel();
                  channelKey = null;
              }
      Severity: Minor
      Found in java/src/com/rubyeventmachine/EventableSocketChannel.java - 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

                  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 @content_length
                      # If there was no content-length header, we have to wait until the connection
                      # closes. Everything we get until that point is content.
                      # TODO: Must impose a content-size limit, and also must implement chunking.
                      # Also, must support either temporary files for large content, or calling
        Severity: Major
        Found in lib/em/protocols/httpclient.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                        will_take = if remaining_data.length > needed
                                      needed
                                    else
                                      remaining_data.length
                                    end
          Severity: Major
          Found in lib/em/protocols/linetext2.rb - About 45 mins to fix

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

                  def receive_line line
                    @stomp_initialized || init_message_reader
                    @stomp_message.consume_line(line) {|outcome|
                      if outcome.first == :sized_text
                        set_text_mode outcome[1]
            Severity: Minor
            Found in lib/em/protocols/stomp.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

              Avoid deeply nested control flow statements.
              Open

                              if @headers.length == 1
                                parse_response_line
                              elsif ary.first =~ /\Acontent-length:\s*/i
                                # Only take the FIRST content-length header that appears,
                                # which we can distinguish because @content_length is nil.
              Severity: Major
              Found in lib/em/protocols/httpclient.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                              if @lt2_textpos >= @lt2_textsize
                                # Reset line mode (the default behavior) BEFORE calling the
                                # receive_binary_data. This makes it possible for user code
                                # to call set_text_mode, enabling chains of text blocks
                                # (which can possibly be of different sizes).
                Severity: Major
                Found in lib/em/protocols/linetext2.rb - About 45 mins to fix

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

                      def handshake_complete?
                        if !@handshake_complete && io.respond_to?(:state)
                          if io.state =~ /^SSLOK/
                            @handshake_complete = true
                            EventMachine::event_callback uuid, SslHandshakeCompleted, ""
                  Severity: Minor
                  Found in lib/em/pure_ruby.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

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

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

                        public void scheduleOutboundData (ByteBuffer bb) {
                            if (!bCloseScheduled && bb.remaining() > 0) {
                                if (sslEngine != null) {
                                    try {
                                        ByteBuffer b = ByteBuffer.allocate(32*1024); // TODO, preallocate this buffer.
                    Severity: Minor
                    Found in java/src/com/rubyeventmachine/EventableSocketChannel.java - 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 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

                    Severity
                    Category
                    Status
                    Source
                    Language