Showing 23 of 23 total issues
Method client
has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring. Open
def client(method, path, host = nil, port = nil, payload = nil, options = {}, observe_callback = nil)
# Set host and port only one time on multiple requests
host.nil? ? (host = @host unless @host.nil?) : @host = host
port.nil? ? (port = @port unless @port.nil?) : @port = port
- 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 client
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
def client(method, path, host = nil, port = nil, payload = nil, options = {}, observe_callback = nil)
# Set host and port only one time on multiple requests
host.nil? ? (host = @host unless @host.nil?) : @host = host
port.nil? ? (port = @port unless @port.nil?) : @port = port
Method initialize
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def initialize(options = {})
@max_retransmit = options[:max_retransmit] || 4
@recv_timeout = options[:recv_timeout] || DEFAULT_RECV_TIMEOUT
@socket = options[:socket]
@force_ipv6 = !!options[:force_ipv6]
- 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 prepare_options
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def prepare_options
prepared_options = {}
options.each do |k, v|
if oinfo_i = CoAP::OPTIONS_I[k]
onum, oname, defv, minmax, rep, _, encoder = *oinfo_i
- 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 parse
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def self.parse(d)
# dpos keeps our current position in parsing d
b1, mcode, mid = d.unpack("CCn"); dpos = 4
toklen = b1 & 0xf
token = d.byteslice(dpos, toklen); dpos += toklen
- 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 request
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def request(message, host, port = CoAP::PORT)
retry_count = 0
retransmit = @retransmit && message.tt == :con
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"
Further reading
Method initialize
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def initialize(*args) # convenience: .new(tt?, mcode?, mid?, payload?, hash?)
if args.size < 6
h = {}
h = args.pop.dup if args.last.is_a? Hash
- 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 to_wire
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_wire
# check and encode option values
prepared_options = prepare_options
token = (prepared_options.delete(CoAP::TOKEN_ON) || [nil])[0] || ''
Method parse
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.parse(d)
# dpos keeps our current position in parsing d
b1, mcode, mid = d.unpack("CCn"); dpos = 4
toklen = b1 & 0xf
token = d.byteslice(dpos, toklen); dpos += toklen
Consider simplifying this complex logical expression. Open
if args.size < 6
h = {}
h = args.pop.dup if args.last.is_a? Hash
tt = h.delete(:tt) || args.shift
Method decode_options_and_put_together
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.decode_options_and_put_together(b1, tt, mcode, mid, options, payload)
# check and decode option values
decoded_options = CoAP::DEFAULTING_OPTIONS.dup
options.each_pair do |k, v|
if oinfo = CoAP::OPTIONS[k]
- 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 client
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def client(method, path, host = nil, port = nil, payload = nil, options = {}, observe_callback = nil)
Method decode_options_and_put_together
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.decode_options_and_put_together(b1, tt, mcode, mid, options, payload)
Method observe
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def observe(path, host, port, callback, payload = nil, options = {})
Method validate_arguments!
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def validate_arguments!(host, port, path, payload)
if host.nil? || host.empty?
fail ArgumentError, 'Argument «host» missing.'
end
- 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 to_wire
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def to_wire
# check and encode option values
prepared_options = prepare_options
token = (prepared_options.delete(CoAP::TOKEN_ON) || [nil])[0] || ''
- 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 observe
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def observe(message, callback, socket)
n = message.options[:observe]
callback.call(socket, message)
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def uint_once(min, max, default = nil)
[default, (min..max), false,
->(a) { CoAP.vlb_decode(a[0]) },
->(v) { v == default ? [] : [CoAP.vlb_encode(v)] }
]
- 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 30.
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
def o256_once(min, max, default = nil)
[default, (min..max), false,
->(a) { CoAP.o256_decode(a[0]) },
->(v) { v == default ? [] : [CoAP.o256_encode(v)] }
]
- 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 30.
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
def o256_many(min, max)
[nil, (min..max), true,
->(a) { a.map{ |x| CoAP.o256_decode(x)} },
->(v) { Array(v).map{ |x| CoAP.o256_encode(x)} }
]
- 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 29.
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