zold-io/zold

View on GitHub

Showing 117 of 117 total issues

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
Severity: Minor
Found in lib/zold/commands/fetch.rb - About 1 hr to fix

    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',
    Severity: Minor
    Found in lib/zold/commands/calculate.rb - About 1 hr to fix

      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]}"
      Severity: Minor
      Found in lib/zold/remotes.rb - About 1 hr to fix

        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
        Severity: Minor
        Found in lib/zold/node/spread_entrance.rb - About 1 hr to fix

          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}
          Severity: Minor
          Found in lib/zold/commands/remote.rb - About 1 hr to fix

          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 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}")
          Severity: Minor
          Found in lib/zold/hungry_wallets.rb - About 1 hr to fix

          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)}"
          Severity: Minor
          Found in lib/zold/json_page.rb - About 1 hr to fix

          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',
          Severity: Minor
          Found in lib/zold/commands/merge.rb - About 1 hr to fix

          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
          Severity: Minor
          Found in lib/zold/commands/node.rb - About 1 hr to fix

          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 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?
          Severity: Minor
          Found in lib/zold/patch.rb - About 1 hr to fix

            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)
            Severity: Minor
            Found in lib/zold/node/async_entrance.rb - About 1 hr to fix

              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'])}"] +
              Severity: Minor
              Found in lib/zold/commands/pay.rb and 1 other location - About 1 hr to fix
              lib/zold/commands/node.rb on lines 337..342

              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

              Further Reading

              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'])}"] +
              Severity: Minor
              Found in lib/zold/commands/node.rb and 1 other location - About 1 hr to fix
              lib/zold/commands/pay.rb on lines 94..99

              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

              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
              Severity: Minor
              Found in lib/zold/commands/routines/gc.rb - About 55 mins to fix

              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?
              Severity: Minor
              Found in lib/zold/remotes.rb - About 55 mins to fix

              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(
                        [
              Severity: Minor
              Found in lib/zold/commands/remote.rb - About 55 mins to fix

              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 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,
              Severity: Minor
              Found in lib/zold/copies.rb - About 55 mins to fix

              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)
              Severity: Minor
              Found in lib/zold/txn.rb - About 45 mins to fix

                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']
                Severity: Minor
                Found in lib/zold/commands/remote.rb - About 45 mins to fix

                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)
                Severity: Minor
                Found in lib/zold/wallet.rb - About 45 mins to fix

                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

                Severity
                Category
                Status
                Source
                Language