Showing 26 of 147 total issues
File pure_ruby.rb
has 863 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'singleton'
require 'forwardable'
require 'socket'
require 'fcntl'
require 'set'
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'
Method receive_data
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
def receive_data data
while data and data.length > 0
case @read_state
when :base
# Perform any per-request initialization here and don't consume any data.
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.
Method start_tls
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def start_tls args={}
priv_key_path = args[:private_key_file]
priv_key = args[:private_key]
priv_key_pass = args[:private_key_pass]
cert_chain_path = args[:cert_chain_file]
Method start_tls
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def start_tls signature
selectable = Reactor.instance.get_selectable(signature) or raise "unknown io selectable for start_tls"
tls_parms = @tls_parms[signature]
ctx = OpenSSL::SSL::SSLContext.new
ctx.options = tls_parms[:ssl_options]
Method set_tls_parms
has 13 arguments (exceeds 4 allowed). Consider refactoring. Open
def set_tls_parms signature, priv_key_path, priv_key, priv_key_pass, cert_chain_path, cert, verify_peer, fail_if_no_peer_cert, sni_hostname, cipher_list, ecdh_curve, dhparam, protocols_bitmask
Similar blocks of code found in 2 locations. Consider refactoring. Open
public Object[] getPeerName (long sig) {
EventableChannel channel = Connections.get(sig);
if (channel != null) {
return Connections.get(sig).getPeerName();
}
- Read upRead up
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 72.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
public Object[] getSockName (long sig) {
EventableChannel channel = Connections.get(sig);
if (channel != null) {
return Connections.get(sig).getSockName();
}
- Read upRead up
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 72.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid deeply nested control flow statements. Open
will_take = if remaining_data.length > needed
needed
else
remaining_data.length
end
Avoid deeply nested control flow statements. Open
if (m = data.match(/\A(\S*)\r\n/m))
data = data[m[0].length..-1]
@chunk_length = m[1].to_i(16)
@chunk_read = 0
if @chunk_length == 0
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
Avoid deeply nested control flow statements. Open
return if t == false # timer cancelled
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
Avoid deeply nested control flow statements. Open
add_define 'WITH_SSL' if find_openssl_library
Avoid deeply nested control flow statements. Open
rescue Exception => error
@wrapped_exception = error
stop
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
Avoid deeply nested control flow statements. Open
if k == "content-length"
@content_length = v.to_i
end
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.
Avoid deeply nested control flow statements. Open
if (@content_length and @content_length > 0) || @chunked || @connection_close
@read_state = :content
else
dispatch_response
@read_state = :base