zold-io/zold

View on GitHub

Showing 108 of 118 total issues

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
Severity: Minor
Found in lib/zold/node/entrance.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 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])
Severity: Minor
Found in upgrades/delete_banned_wallets.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

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
Severity: Minor
Found in lib/zold/age.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 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?)
Severity: Minor
Found in lib/zold/signature.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 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('@')
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

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"
Severity: Minor
Found in lib/zold/node/async_entrance.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 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(
Severity: Minor
Found in lib/zold/node/pipeline.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 pay has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def pay(from, invoice, amount, details, opts)
Severity: Minor
Found in lib/zold/commands/pay.rb - About 35 mins to fix

    Method existing_copy_added has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def existing_copy_added(id, cps, score, r, json)
    Severity: Minor
    Found in lib/zold/commands/fetch.rb - About 35 mins to fix

      Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def initialize(opts, wallets, remotes, copies, address, log: Log::NULL)
      Severity: Minor
      Found in lib/zold/commands/routines/reconcile.rb - About 35 mins to fix

        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)
        Severity: Minor
        Found in lib/zold/node/async_entrance.rb - About 35 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 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
        Severity: Minor
        Found in lib/zold/commands/remote.rb - About 35 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 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
        Severity: Minor
        Found in lib/zold/commands/remove.rb - About 35 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 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")
        Severity: Minor
        Found in upgrades/protocol_up.rb - About 35 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 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)
        Severity: Minor
        Found in upgrades/rename_foreign_wallets.rb - About 35 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 select has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def select(opts)
              @remotes.all.shuffle.sort_by { |r| r[:errors] }.reverse.each_with_index do |r, idx|
                next if idx < opts['max-nodes']
                next if r[:master] && !opts['masters-too']
                @remotes.remove(r[:host], r[:port])
        Severity: Minor
        Found in lib/zold/commands/remote.rb - About 35 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

        Avoid too many return statements within this method.
        Open

              return "#{(days / 30).round}mo" if days < 365
        Severity: Major
        Found in lib/zold/age.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                return "#{days}d" if days < 14
          Severity: Major
          Found in lib/zold/age.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                  return "#{(days / 7).round}w" if days < 40
            Severity: Major
            Found in lib/zold/age.rb - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language