yegor256/sibit

View on GitHub

Showing 14 of 14 total issues

Method scan has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def scan(start, max: 4)
    raise Error, "Invalid block hash #{start.inspect}" unless /^[0-9a-f]{64}$/.match?(start)
    raise Error, "The max number must be above zero: #{max}" if max < 1
    block = start
    count = 0
Severity: Minor
Found in lib/sibit.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 scan has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def scan(start, max: 4)
    raise Error, "Invalid block hash #{start.inspect}" unless /^[0-9a-f]{64}$/.match?(start)
    raise Error, "The max number must be above zero: #{max}" if max < 1
    block = start
    count = 0
Severity: Major
Found in lib/sibit.rb - About 2 hrs to fix

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

      def pay(amount, fee, sources, target, change, skip_utxo: [])
        p = price('USD')
        satoshi = satoshi(amount)
        builder = Bitcoin::Builder::TxBuilder.new
        unspent = 0
    Severity: Major
    Found in lib/sibit.rb - About 2 hrs to fix

      Method pay has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        def pay(amount, fee, sources, target, change, skip_utxo: [])
          p = price('USD')
          satoshi = satoshi(amount)
          builder = Bitcoin::Builder::TxBuilder.new
          unspent = 0
      Severity: Minor
      Found in lib/sibit.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 utxos has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def utxos(sources)
            txns = []
            sources.each do |hash|
              json = Sibit::Json.new(http: @http, log: @log).get(
                Iri.new('https://chain.api.btc.com/v3/address').append(hash).append('unspent')
      Severity: Minor
      Found in lib/sibit/btc.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 first_of has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def first_of(method)
            return yield @list unless @list.is_a?(Array)
            errors = []
            done = false
            result = nil
      Severity: Minor
      Found in lib/sibit/firstof.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 get has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def get(address, headers: {}, accept: [200])
            start = Time.now
            uri = URI(address.to_s)
            res = @http.client(uri).get(
              "#{uri.path.empty? ? '/' : uri.path}#{uri.query ? "?#{uri.query}" : ''}",
      Severity: Minor
      Found in lib/sibit/json.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 txns has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def txns(hash)
            page = 1
            psize = 50
            all = []
            loop do
      Severity: Minor
      Found in lib/sibit/btc.rb - About 1 hr to fix

        Method block has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def block(hash)
              head = Sibit::Json.new(http: @http, log: @log).get(
                Iri.new('https://api-r.bitcoinchain.com/v1/block').append(hash)
              )[0]
              raise Sibit::Error, "The block #{hash} is not found" if head.nil?
        Severity: Minor
        Found in lib/sibit/bitcoinchain.rb - About 1 hr to fix

          Method utxos has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def utxos(sources)
                txns = []
                sources.each do |hash|
                  json = Sibit::Json.new(http: @http, log: @log).get(
                    Iri.new('https://chain.api.btc.com/v3/address').append(hash).append('unspent')
          Severity: Minor
          Found in lib/sibit/btc.rb - About 1 hr to fix

            Method best_of has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def best_of(method)
                  return yield @list unless @list.is_a?(Array)
                  results = []
                  errors = []
                  @list.each do |api|
            Severity: Minor
            Found in lib/sibit/bestof.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(amount, fee, sources, target, change, skip_utxo: [])
            Severity: Minor
            Found in lib/sibit.rb - About 35 mins to fix

              Method txns has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def txns(hash)
                    page = 1
                    psize = 50
                    all = []
                    loop do
              Severity: Minor
              Found in lib/sibit/btc.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 mfee has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def mfee(fee, size)
                  return fee.to_i if fee.is_a?(Integer)
                  raise Error, 'Fee should either be a String or Integer' unless fee.is_a?(String)
                  mul = 1
                  if fee.start_with?('+', '-')
              Severity: Minor
              Found in lib/sibit.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