File protocol.rb
has 575 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "socket"
require "timeout"
require "digest/sha1"
require "stringio"
Class Protocol
has 32 methods (exceeds 20 allowed). Consider refactoring. Open
class Protocol
VERSION = 10
MAX_PACKET_LENGTH = 2**24-1
Method read
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def read
data = ''
len = nil
begin
Timeout.timeout @read_timeout do
- Read upRead up
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 net2value
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def self.net2value(pkt, type, unsigned)
case type
when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB, Field::TYPE_JSON
return pkt.lcs
when Field::TYPE_TINY
- Read upRead up
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 net2value
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.net2value(pkt, type, unsigned)
case type
when Field::TYPE_STRING, Field::TYPE_VAR_STRING, Field::TYPE_NEWDECIMAL, Field::TYPE_BLOB, Field::TYPE_JSON
return pkt.lcs
when Field::TYPE_TINY
Method value2net
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.value2net(v)
case v
when nil
type = Field::TYPE_NULL
val = ""
Method read
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def read
data = ''
len = nil
begin
Timeout.timeout @read_timeout do
Method write
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def write(data)
begin
@sock.sync = false
if data.nil?
Timeout.timeout @write_timeout do
Method parse_record_packet
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def parse_record_packet
@packet.utiny # skip first byte
null_bit_map = @packet.read((@fields.length+7+2)/8).unpack("b*").first
rec = @fields.each_with_index.map do |f, i|
if null_bit_map[i+2] == ?1
- Read upRead up
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 initialize
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
@insert_id = 0
@warning_count = 0
@gc_stmt_queue = [] # stmt id list which GC destroy.
set_state :INIT
- Read upRead up
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 value2net
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.value2net(v)
case v
when nil
type = Field::TYPE_NULL
val = ""
- Read upRead up
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 initialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(host, port, socket, conn_timeout, read_timeout, write_timeout)
Method serialize
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.serialize(client_flags, max_packet_size, charset_number, username, scrambled_password, databasename)
Method authenticate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def authenticate(user, passwd, db, flag, charset)
Method to_a
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def to_a
@fields.map do |f|
if s = @packet.lcs
unless f.type == Field::TYPE_BIT or f.charsetnr == Charset::BINARY_CHARSET_NUMBER
s = Charset.convert_encoding(s, @encoding)
- Read upRead up
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 write
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def write(data)
begin
@sock.sync = false
if data.nil?
Timeout.timeout @write_timeout do
- Read upRead up
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 pkt.lcs
Avoid too many return
statements within this method. Open
return unsigned ? v : v < 0x8000_0000_0000_0000 ? v : v-0x10000_0000_0000_0000
Avoid too many return
statements within this method. Open
return RbMysql::Time.new(0, 0, 0, h, mi, s, sign!=0, sp)
Avoid too many return
statements within this method. Open
return t
Avoid too many return
statements within this method. Open
return RbMysql::Time.new(y, m, d, h, mi, s, false, sp)
Avoid too many return
statements within this method. Open
return pkt.ushort
Avoid too many return
statements within this method. Open
return pkt.read(4).unpack('e').first
Avoid too many return
statements within this method. Open
return pkt.read(8).unpack('E').first
Method set_state
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def set_state(st)
@state = st
if st == :READY
gc_disabled = GC.disable
begin
- Read upRead up
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"