lncm/invoicer

View on GitHub

Showing 11 of 11 total issues

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

    LightningClient interface {
        NewAddress(ctx context.Context, bech32 bool) (string, error)
        Info(ctx context.Context) (common.Info, error)
        NewInvoice(ctx context.Context, amount int64, desc string) (string, string, error)
        Status(ctx context.Context, hash string) (common.Status, error)
Severity: Major
Found in main.go and 1 other location - About 2 hrs to fix
ln/ln.go on lines 9..16

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

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

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

type LightningClient interface {
    NewAddress(ctx context.Context, bech32 bool) (string, error)
    Info(ctx context.Context) (common.Info, error)
    NewInvoice(ctx context.Context, amount int64, desc string) (string, string, error)
    Status(ctx context.Context, hash string) (common.Status, error)
Severity: Major
Found in ln/ln.go and 1 other location - About 2 hrs to fix
main.go on lines 32..39

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

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

Function newPayment has 78 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func newPayment(c *gin.Context) {
    var data struct {
        Amount      int64  `json:"amount"`
        Description string `json:"desc"`
        Only        string `json:"only"`
Severity: Major
Found in main.go - About 2 hrs to fix

    Function history has 77 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func history(c *gin.Context) {
        var queryParams struct {
            Limit      int64  `form:"limit"`
            Offset     int64  `form:"offset"`
            OnlyStatus string `form:"only_status" validate:"omitempty,oneof=paid expired pending"`
    Severity: Major
    Found in main.go - About 2 hrs to fix

      Function history has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
      Open

      func history(c *gin.Context) {
          var queryParams struct {
              Limit      int64  `form:"limit"`
              Offset     int64  `form:"offset"`
              OnlyStatus string `form:"only_status" validate:"omitempty,oneof=paid expired pending"`
      Severity: Minor
      Found in main.go - 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

      Function status has 67 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func status(c *gin.Context) {
          var queryParams struct {
              Hash     string `form:"hash"`
              Addr     string `form:"address"`
              Flexible bool   `form:"flexible"`
      Severity: Minor
      Found in main.go - About 1 hr to fix

        Function init has 57 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func init() {
            flag.Parse()
        
            versionString := "debug"
            if version != "" && gitHash != "" {
        Severity: Minor
        Found in main.go - About 1 hr to fix

          Function checkBtcStatus has 7 return statements (exceeds 4 allowed).
          Open

          func checkBtcStatus(ctx context.Context, fin time.Time, addr string, lnProvided, flexible bool, desiredAmount int64) *common.StatusReply {
              for time.Now().Before(fin) {
                  time.Sleep(2 * time.Second)
          
                  if ctx.Err() != nil {
          Severity: Major
          Found in main.go - About 45 mins to fix

            Method Bitcoind.sendRequest has 7 return statements (exceeds 4 allowed).
            Open

            func (b Bitcoind) sendRequest(method string, params ...interface{}) (response []byte, err error) {
                reqBody, err := json.Marshal(requestBody{
                    JSONRPC: "1.0",
                    Method:  method,
                    Params:  params,
            Severity: Major
            Found in bitcoind/client.go - About 45 mins to fix

              Function newPayment has 7 return statements (exceeds 4 allowed).
              Open

              func newPayment(c *gin.Context) {
                  var data struct {
                      Amount      int64  `json:"amount"`
                      Description string `json:"desc"`
                      Only        string `json:"only"`
              Severity: Major
              Found in main.go - About 45 mins to fix

                Function checkBtcStatus has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func checkBtcStatus(ctx context.Context, fin time.Time, addr string, lnProvided, flexible bool, desiredAmount int64) *common.StatusReply {
                Severity: Minor
                Found in main.go - About 35 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language