Method read_response
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
def read_response(t = -1, opts = {})
# Return a nil response if timeout is nil or 0
return if t.nil? || t == 0
resp = Response.new
- 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
File client.rb
has 509 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'rex/socket'
require 'rex/text'
require 'digest'
Method send_auth
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def send_auth(res, opts, t, persist)
if opts['username'].nil? or opts['username'] == ''
if self.username and not (self.username == '')
opts['username'] = self.username
opts['password'] = self.password
- 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 digest_auth
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
def digest_auth(opts={})
cnonce = make_cnonce
nonce_count = 0
to = opts['timeout'] || 20
Method digest_auth
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
def digest_auth(opts={})
cnonce = make_cnonce
nonce_count = 0
to = opts['timeout'] || 20
- 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 negotiate_auth
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def negotiate_auth(opts={})
to = opts['timeout'] || 20
opts['username'] ||= ''
opts['password'] ||= ''
- 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 read_response
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
def read_response(t = -1, opts = {})
# Return a nil response if timeout is nil or 0
return if t.nil? || t == 0
resp = Response.new
Class Client
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
class Client
#
# Creates a new client instance
# @param http_trace_proc_request [Proc] A proc object passed to log HTTP requests if HTTP-Trace is set
Method negotiate_auth
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def negotiate_auth(opts={})
to = opts['timeout'] || 20
opts['username'] ||= ''
opts['password'] ||= ''
Method send_auth
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
def send_auth(res, opts, t, persist)
if opts['username'].nil? or opts['username'] == ''
if self.username and not (self.username == '')
opts['username'] = self.username
opts['password'] = self.password
Method initialize
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil, username = '', password = '', kerberos_authenticator: nil, comm: nil, subscriber: nil)
self.hostname = host
self.port = port.to_i
self.context = context
self.ssl = ssl
Method kerberos_auth
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def kerberos_auth(opts={})
to = opts['timeout'] || 20
auth_result = self.kerberos_authenticator.authenticate(mechanism: Rex::Proto::Gss::Mechanism::KERBEROS)
gss_data = auth_result[:security_blob]
gss_data_b64 = Rex::Text.encode_base64(gss_data)
Method set_config
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def set_config(opts = {})
opts.each_pair do |var,val|
# Default type is string
typ = self.config_types[var] || 'string'
- 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 8 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil, username = '', password = '', kerberos_authenticator: nil, comm: nil, subscriber: nil)
Method kerberos_auth
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def kerberos_auth(opts={})
to = opts['timeout'] || 20
auth_result = self.kerberos_authenticator.authenticate(mechanism: Rex::Proto::Gss::Mechanism::KERBEROS)
gss_data = auth_result[:security_blob]
gss_data_b64 = Rex::Text.encode_base64(gss_data)
- 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 deeply nested control flow statements. Open
if temp_response.kind_of? Rex::Proto::Http::Response
res = temp_response
end
Method _send_recv
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _send_recv(req, t = -1, persist = false)
@pipeline = persist
subscriber.on_request(req)
if req.respond_to?(:opts) && req.opts['ntlm_transform_request'] && self.ntlm_client
req = req.opts['ntlm_transform_request'].call(self.ntlm_client, req)
- 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 connect
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def connect(t = -1)
# If we already have a connection and we aren't pipelining, close it.
if (self.conn)
if !pipelining?
close
- 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 res
Avoid too many return
statements within this method. Open
return resp
Avoid too many return
statements within this method. Open
return resp
Avoid too many return
statements within this method. Open
return res
Avoid too many return
statements within this method. Open
return nil
Avoid too many return
statements within this method. Open
return res
Similar blocks of code found in 2 locations. Consider refactoring. Open
rescue ::Errno::EPIPE, ::EOFError, ::IOError
case resp.state
when Packet::ParseState::ProcessingHeader
resp = nil
when Packet::ParseState::ProcessingBody
- 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 25.
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