Showing 118 of 118 total issues
Method exec
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.exec(threads, set = (0..threads - 1).to_a, &block)
raise 'The thread pool is empty' if POOL.empty?
raise "Number of threads #{threads} has to be positive" unless threads.positive?
list = set.dup
total = [threads, set.count].min
Method merge_one
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def merge_one(opts, patch, wallet, name, baseline: false, master: false)
start = Time.now
@log.debug("Adding copy ##{name}#{master ? ' (master)' : ''} to the patch #{wallet.mnemo}...")
if opts['depth'].positive?
patch.join(wallet, ledger: opts['ledger'], baseline: baseline, master: master) do |txn|
Method run
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run(args = [])
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
o.banner = "Usage: zold push [ID...] [options]
Available options:"
o.bool '--ignore-score-weakness',
Method run
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run(args = [])
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
o.banner = "Usage: zold score [options]
Available options:"
o.string '--time',
Method fetch_one
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def fetch_one(id, r, cps, opts)
if opts['ignore-node'].include?(r.to_s)
@log.debug("#{r} ignored because of --ignore-node")
return 0
end
Method iterate
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def iterate(log, farm: Farm::Empty.new, threads: 1)
raise 'Log can\'t be nil' if log.nil?
raise 'Farm can\'t be nil' if farm.nil?
Hands.exec(threads, all) do |r, idx|
Thread.current.name = "remotes-#{idx}@#{r[:host]}:#{r[:port]}"
Method start
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def start
raise 'Block must be given to start()' unless block_given?
@entrance.start do
@seen = Set.new
@modified = Queue.new
Method acq
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def acq(id, exclusive: false)
@wallets.acq(id, exclusive: exclusive) do |wallet|
unless wallet.exists?
if @queue.size > 256
@log.error("Hungry queue is full with #{@queue.size} wallets, can't add #{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 to_hash
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def to_hash
raise CantParse, "JSON is empty, can't parse#{@uri.empty? ? '' : " at #{@uri}"}" if @text.empty?
JSON.parse(@text)
rescue JSON::ParserError => e
raise CantParse, "Failed to parse JSON #{@uri.empty? ? '' : "at #{@uri}"} (#{short(e.message)}): #{short(@text)}"
- 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 metronome
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def metronome(farm, opts, host, port)
metronome = Metronome.new(@log)
if opts['no-metronome']
@log.info("Metronome hasn't been started because of --no-metronome")
return metronome
- 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 run
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def run(args = [])
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
o.banner = "Usage: zold merge [ID...] [options]
Available options:"
o.bool '--skip-propagate',
- 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 run
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def run(args = [])
opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
o.banner = "Usage: zold remote <command> [options]
Available commands:
#{Rainbow('remote show').green}
- 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 start
has 26 lines of code (exceeds 25 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)
Method save
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save(file, overwrite: false, allow_negative_balance: false)
raise 'You have to join at least one wallet in' if empty?
before = ''
wallet = Wallet.new(file)
before = wallet.digest if wallet.exists?
Similar blocks of code found in 2 locations. Consider refactoring. Open
unless invoice.include?('@')
require_relative 'invoice'
invoice = Invoice.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
['invoice', invoice, "--tolerate-quorum=#{Shellwords.escape(opts['tolerate-quorum'])}"] +
["--network=#{Shellwords.escape(opts['network'])}"] +
- 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 47.
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
invoice = opts['invoice']
unless invoice.include?('@')
require_relative 'invoice'
invoice = Invoice.new(wallets: @wallets, remotes: @remotes, copies: @copies, log: @log).run(
['invoice', invoice, "--network=#{Shellwords.escape(opts['network'])}"] +
- 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 47.
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 all
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def all(masters_first: true)
Futex.new(file, log: @log).open(false) do
list = load.group_by { |s| s[:name] }.map do |name, scores|
{
name: name,
- 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 assert_host_info
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def assert_host_info(host, port)
raise 'Host can\'t be nil' if host.nil?
raise 'Host can\'t be empty' if host.empty?
raise 'Host IP is wrong, can\'t be all zeros' if host == '0.0.0.0'
raise 'Port can\'t be nil' if port.nil?
- 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 9 (exceeds 5 allowed). Consider refactoring. Open
def exec(_ = 0)
sleep(60) unless @opts['routine-immediately']
cmd = Zold::Remove.new(wallets: @wallets, log: @log)
args = ['remove']
seen = 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 show
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def show
@remotes.all.each do |r|
score = Rainbow("/#{r[:score]}").color(r[:score].positive? ? :green : :red)
@log.info(
[
- 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"