zold-io/zold

View on GitHub

Showing 108 of 118 total issues

Method up has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

      def up(score)
        start = Time.now
        bin = File.expand_path(File.join(File.dirname(__FILE__), '../../../bin/zold'))
        raise "Zold binary not found at #{bin}" unless File.exist?(bin)
        cmd = [
Severity: Minor
Found in lib/zold/node/farmers.rb - About 2 hrs 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 iterate has a Cognitive Complexity of 19 (exceeds 5 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 2 hrs 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 nohup has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def nohup(opts)
      pid = fork do
        nohup_log = NohupLog.new(opts['nohup-log'], opts['nohup-log-truncate'])
        Signal.trap('HUP') do
          nohup_log.print("Received HUP, ignoring...\n")
Severity: Minor
Found in lib/zold/commands/node.rb - About 2 hrs 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 17 (exceeds 5 allowed). Consider refactoring.
Open

    def add(content, host, port, score, time: Time.now, master: false)
      raise "Content can't be empty" if content.empty?
      raise 'TCP port must be of type Integer' unless port.is_a?(Integer)
      raise "TCP port can't be negative: #{port}" if port.negative?
      raise 'Time must be of type Time' unless time.is_a?(Time)
Severity: Minor
Found in lib/zold/copies.rb - About 2 hrs 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 fetch has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def fetch(id, cps, opts)
      if @remotes.all.empty?
        return if opts['quiet-if-absent']
        raise "There are no remote nodes, run 'zold remote reset'"
      end
Severity: Minor
Found in lib/zold/commands/fetch.rb - About 2 hrs 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 taxes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def taxes(id, opts)
      debt = @wallets.acq(id) do |wallet|
        raise "Wallet #{id} doesn't exist, do 'zold pull' first" unless wallet.exists?
        Tax.new(wallet).in_debt? && !opts['dont-pay-taxes']
      end
Severity: Minor
Found in lib/zold/commands/pay.rb - About 2 hrs 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 55 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 taxes command [options]
Available commands:
    #{Rainbow('taxes pay').green} wallet
Severity: Major
Found in lib/zold/commands/taxes.rb - About 2 hrs to fix

    Method clean has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def clean(max: 24 * 60 * 60)
          Futex.new(file, log: @log).open do
            list = load
            list.reject! do |s|
              if s[:time] >= Time.now - max
    Severity: Minor
    Found in lib/zold/copies.rb - About 2 hrs 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 push has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def push(id, opts)
          raise "There are no remote nodes, run 'zold remote reset'" if @remotes.all.empty?
          @wallets.acq(id) do |wallet|
            raise "The wallet #{id} is absent at #{wallet.path}" unless wallet.exists?
          end
    Severity: Minor
    Found in lib/zold/commands/push.rb - About 2 hrs 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

    File remotes.rb has 251 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'concurrent'
    require 'csv'
    require 'uri'
    require 'net/http'
    require 'time'
    Severity: Minor
    Found in lib/zold/remotes.rb - About 2 hrs to fix

      Method run has 49 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 merge [ID...] [options]
      Available options:"
              o.bool '--skip-propagate',
      Severity: Minor
      Found in lib/zold/commands/merge.rb - About 1 hr to fix

        Method push has a Cognitive Complexity of 15 (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?
              Tempfile.open(['', Wallet::EXT]) do |f|
        Severity: Minor
        Found in lib/zold/node/safe_entrance.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 a Cognitive Complexity of 15 (exceeds 5 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

        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 cycle has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def cycle(host, port, threads)
              s = []
              loop do
                begin
                  s << @pipeline.pop(true)
        Severity: Minor
        Found in lib/zold/node/farm.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 calculate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def calculate(opts)
              start = Time.now
              mstart = Time.now
              strength = opts[:strength]
              raise "Invalid strength: #{strength}" if strength <= 0 || strength > 8
        Severity: Minor
        Found in lib/zold/commands/calculate.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 up has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def up(score)
                start = Time.now
                bin = File.expand_path(File.join(File.dirname(__FILE__), '../../../bin/zold'))
                raise "Zold binary not found at #{bin}" unless File.exist?(bin)
                cmd = [
        Severity: Minor
        Found in lib/zold/node/farmers.rb - About 1 hr to fix

          Method merge has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def merge(id, cps, opts)
                start = Time.now
                cps = cps.all(masters_first: !opts['edge-baseline'])
                patch = Patch.new(@wallets, log: @log)
                score = 0
          Severity: Minor
          Found in lib/zold/commands/merge.rb - About 1 hr to fix

            Method pay has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def pay(wallet, opts)
                  raise 'The wallet is absent' unless wallet.exists?
                  tax = Tax.new(wallet)
                  debt = total = tax.debt
                  @log.info("The current debt of #{wallet.mnemo} is #{debt} (#{debt.to_i} zents), \
            Severity: Minor
            Found in lib/zold/commands/taxes.rb - About 1 hr to fix

              Method start has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  def start(host, port, threads: Concurrent.processor_count)
                    raise 'Block is required for the farm to start' unless block_given?
                    @log.info('Zero-threads farm won\'t score anything!') if threads.zero?
                    if best.empty?
                      @log.info("No scores found in the cache at #{@cache}")
              Severity: Minor
              Found in lib/zold/node/farm.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 initialize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  def initialize(file: nil, text: nil)
                    @body = lambda do
                      unless file.nil?
                        path = File.expand_path(file)
                        raise "Can't find RSA key at #{file} (#{path})" unless File.exist?(path)
              Severity: Minor
              Found in lib/zold/key.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

              Severity
              Category
              Status
              Source
              Language