zold-io/zold

View on GitHub

Showing 118 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 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 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 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 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 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 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 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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            head = r.http(uri).get
            raise Fetch::Error, "The wallet #{id} doesn't exist at #{r}" if head.status == 404
            r.assert_code(200, head)
            json = JsonPage.new(head.body, uri).to_hash
            score = Score.parse_json(json['score'])
    Severity: Minor
    Found in lib/zold/commands/fetch.rb and 1 other location - About 45 mins to fix
    lib/zold/commands/push.rb on lines 162..169

    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 39.

    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

            r.assert_code(200, response)
            json = JsonPage.new(response.body, uri).to_hash
            score = Score.parse_json(json['score'])
            yield json, score
          rescue JsonPage::CantParse, Score::CantParse, RemoteNode::CantAssert => e
    Severity: Minor
    Found in lib/zold/commands/push.rb and 1 other location - About 45 mins to fix
    lib/zold/commands/fetch.rb on lines 187..194

    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 39.

    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 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 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

          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 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

          Severity
          Category
          Status
          Source
          Language