zold-io/zold

View on GitHub
lib/zold/wallet.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class Wallet has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Wallet
    # The name of the main production network. All other networks
    # must have different names.
    MAINET = 'zold'

Severity: Minor
Found in lib/zold/wallet.rb - About 3 hrs to fix

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

    There are no issues that match your filters.

    Category
    Status