Showing 118 of 118 total issues
Method reboot
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def reboot(r, json, opts)
return unless json['repo'] == Zold::REPO
mine = Semantic::Version.new(VERSION)
if mine < Semantic::Version.new(json['version'])
if opts['reboot']
- 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(id, date, amount, prefix, bnf, details)
Method push
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def push(id, body)
raise 'Id can\'t be nil' if id.nil?
raise 'Id must be of type Id' unless id.is_a?(Id)
raise 'Body can\'t be nil' if body.nil?
start = Time.now
- 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 exec
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def exec
DirItems.new(@home).fetch.each do |path|
name = File.basename(path)
next unless name =~ /^[a-f0-9]{16}#{Wallet::EXT}$/
id = Id.new(name[0..15])
- 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 add
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def add(txn)
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
raise "The amount can't be zero in #{id}: #{txn}" if txn.amount.zero?
if txn.amount.negative? && includes_negative?(txn.id)
- 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 text
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def text(sec)
return "#{(sec * 1_000_000).round}μs" if sec < 0.001
return "#{(sec * 1000).round}ms" if sec < 1
return "#{sec.round(2)}s" if sec < 60
return "#{(sec / 60).round}m" if sec < 60 * 60
- 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 valid?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def valid?(pub, id, txn)
raise 'pub must be of type Key' unless pub.is_a?(Key)
raise 'id must be of type Id' unless id.is_a?(Id)
raise 'txn must be of type Txn' unless txn.is_a?(Txn)
pub.verify(txn.sign, body(id, txn)) && (@network != Wallet::MAINET || !id.root? || pub.root?)
- 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 sub
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def sub(amount, invoice, pvt, details = '-', time: Time.now)
raise 'The amount has to be of type Amount' unless amount.is_a?(Amount)
raise "The amount can't be negative: #{amount}" if amount.negative?
raise 'The pvt has to be of type Key' unless pvt.is_a?(Key)
prefix, target = invoice.split('@')
- 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 push
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def push(id, body)
if @queue.size > @queue_limit
raise(
SoftError,
"Queue is too long (#{@queue.size} wallets), can't add #{id}/#{Size.new(body.length)}, try again later"
- 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 merge
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def merge(id, copies, wallets, log)
Tempfile.open do |f|
modified = Tempfile.open do |t|
host, port = @address.split(':')
Merge.new(wallets: wallets, remotes: @remotes, copies: copies.root, log: log).run(
- 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
r.assert_code(200, response)
json = JsonPage.new(response.body, uri).to_hash
score = Score.parse_json(json['score'])
yield json, score
rescue JsonPage::CantParse, Score::CantParse, RemoteNode::CantAssert => e
- 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 39.
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
head = r.http(uri).get
raise Fetch::Error, "The wallet #{id} doesn't exist at #{r}" if head.status == 404
r.assert_code(200, head)
json = JsonPage.new(head.body, uri).to_hash
score = Score.parse_json(json['score'])
- 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 39.
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
Method pay
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def pay(from, invoice, amount, details, opts)
Method existing_copy_added
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def existing_copy_added(id, cps, score, r, json)
Method initialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def initialize(opts, wallets, remotes, copies, address, log: Log::NULL)
Method start
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def start
raise 'Block must be given to start()' unless block_given?
FileUtils.mkdir_p(@dir)
DirItems.new(@dir).fetch.each do |f|
file = File.join(@dir, f)
- 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 add
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add(host, port, opts)
if opts['ignore-node'].include?("#{host}:#{port}")
@log.debug("#{host}:#{port} won't be added since it's in the --ignore-node list")
return
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 remove
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def remove(id, opts)
@wallets.acq(id, exclusive: true) do |w|
if w.exists?
File.delete(w.path)
else
- 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 exec
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def exec
Dir.new(@home).each do |path|
next unless path =~ /^[a-f0-9]{16}#{Wallet::EXT}$/
f = File.join(@home, path)
lines = File.read(f).split("\n")
- 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 exec
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def exec
Dir.new(@home).each do |path|
next unless path =~ /^[a-f0-9]{16}#{Wallet::EXT}$/
f = File.join(@home, path)
wallet = Wallet.new(f)
- 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"