zold-io/zold

View on GitHub

Showing 118 of 118 total issues

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

    def fetch
      raise "Wallet file '#{@file}' is absent" unless File.exist?(@file)
      txns = []
      i = 0
      File.open(@file) do |f|
Severity: Minor
Found in lib/zold/txns.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 pay has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def pay(from, invoice, amount, details, opts)
      unless opts.force?
        raise 'The amount can\'t be zero' if amount.zero?
        raise "The amount can't be negative: #{amount}" if amount.negative?
        if !from.root? && from.balance < amount
Severity: Minor
Found in lib/zold/commands/pay.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 update has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def update(opts)
      st = Time.now
      seen = Set.new
      capacity = []
      opts['depth'].times do
Severity: Minor
Found in lib/zold/commands/remote.rb - About 1 hr to fix

    Method add has 38 lines of code (exceeds 25 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 1 hr to fix

      Method start has 38 lines of code (exceeds 25 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

        Method clean has 37 lines of code (exceeds 25 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 1 hr to fix

          Method metronome has 37 lines of code (exceeds 25 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

            Method propagate has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def propagate(id, _)
                  start = Time.now
                  modified = []
                  total = 0
                  network = @wallets.acq(id, &:network)
            Severity: Minor
            Found in lib/zold/commands/propagate.rb - About 1 hr to fix

              Method exec has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                def exec(_ = 0)
                  sleep(20 * 60) unless @opts['routine-immediately']
                  @remotes.iterate(@log) do |r|
                    next unless r.master?
                    next if r.to_mnemo == @address
              Severity: Minor
              Found in lib/zold/commands/routines/reconcile.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 elect has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def elect(opts)
                    scores = []
                    @remotes.iterate(@log, farm: @farm, threads: opts['threads']) do |r|
                      uri = '/'
                      res = r.http(uri).get
              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 12 (exceeds 5 allowed). Consider refactoring.
              Open

                    def acq(id, exclusive: false)
                      @wallets.acq(id, exclusive: exclusive) do |wallet|
                        return yield wallet unless exclusive
                        before = wallet.exists? ? File.read(wallet.path) : ''
                        res = yield wallet
              Severity: Minor
              Found in lib/zold/node/journaled_pipeline.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 nohup has 35 lines of code (exceeds 25 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 1 hr to fix

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

                  Method fetch has 33 lines of code (exceeds 25 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 1 hr to fix

                    Method push has 32 lines of code (exceeds 25 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 1 hr to fix

                      Method initialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def initialize(zents: nil, zld: nil)
                            if !zents.nil?
                              raise "Integer is required, while #{zents.class} provided: #{zents}" unless zents.is_a?(Integer)
                              @zents = zents
                            elsif !zld.nil?
                      Severity: Minor
                      Found in lib/zold/amount.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 create_id has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def create_id(opts)
                            loop do
                              id = Id.new
                              return id if opts['skip-test']
                              found = @wallets.exists?(id)
                      Severity: Minor
                      Found in lib/zold/commands/create.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 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def run(args = [])
                            opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
                              o.banner = "Usage: zold pay wallet target amount [details] [options]
                      Where:
                          'wallet' is the sender's wallet ID
                      Severity: Minor
                      Found in lib/zold/commands/pay.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 11 (exceeds 5 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: Minor
                      Found in lib/zold/commands/taxes.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 exec has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def exec(step = 0)
                          sleep(60) unless @opts['routine-immediately']
                          cmd = Zold::Remote.new(remotes: @remotes, log: @log, farm: @farm)
                          args = ['remote', "--network=#{Shellwords.escape(@opts['network'])}", '--ignore-ping']
                          score = @farm.best[0]
                      Severity: Minor
                      Found in lib/zold/commands/routines/reconnect.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