nuts-foundation/nuts-consent-logic

View on GitHub
pkg/logic.go

Summary

Maintainability
D
2 days
Test Coverage

Method ConsentLogic.HandleIncomingCordaEvent has a Cognitive Complexity of 45 (exceeds 20 allowed). Consider refactoring.
Open

func (cl ConsentLogic) HandleIncomingCordaEvent(event *events.Event) {
    logger().Infof("received event %v", event)

    crs := bridgeClient.FullConsentRequestState{}
    decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
Severity: Minor
Found in pkg/logic.go - About 4 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 ConsentLogic.HandleIncomingCordaEvent has 102 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (cl ConsentLogic) HandleIncomingCordaEvent(event *events.Event) {
    logger().Infof("received event %v", event)

    crs := bridgeClient.FullConsentRequestState{}
    decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
Severity: Major
Found in pkg/logic.go - About 3 hrs to fix

    Method ConsentLogic.buildConsentRequestConstructedEvent has 96 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (cl ConsentLogic) buildConsentRequestConstructedEvent(createConsentRequest *CreateConsentRequest) (*events.Event, error) {
        var err error
        var consentID string
        var records []bridgeClient.ConsentRecord
        legalEntities := []bridgeClient.Identifier{
    Severity: Major
    Found in pkg/logic.go - About 2 hrs to fix

      File logic.go has 519 lines of code (exceeds 500 allowed). Consider refactoring.
      Open

      /*
       *  Nuts consent logic holds the logic for consent creation
       *  Copyright (C) 2019 Nuts community
       *
       *  This program is free software: you can redistribute it and/or modify
      Severity: Minor
      Found in pkg/logic.go - About 2 hrs to fix

        Method ConsentLogic.signConsentRequest has 64 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (cl ConsentLogic) signConsentRequest(event events.Event) (*events.Event, error) {
            crs := bridgeClient.FullConsentRequestState{}
            decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
            if err != nil {
                errorDescription := "Could not base64 decode event payload"
        Severity: Minor
        Found in pkg/logic.go - About 1 hr to fix

          Method ConsentLogic.signConsentRequest has 9 return statements (exceeds 4 allowed).
          Open

          func (cl ConsentLogic) signConsentRequest(event events.Event) (*events.Event, error) {
              crs := bridgeClient.FullConsentRequestState{}
              decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
              if err != nil {
                  errorDescription := "Could not base64 decode event payload"
          Severity: Major
          Found in pkg/logic.go - About 55 mins to fix

            Method ConsentLogic.HandleIncomingCordaEvent has 8 return statements (exceeds 4 allowed).
            Open

            func (cl ConsentLogic) HandleIncomingCordaEvent(event *events.Event) {
                logger().Infof("received event %v", event)
            
                crs := bridgeClient.FullConsentRequestState{}
                decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
            Severity: Major
            Found in pkg/logic.go - About 50 mins to fix

              Method ConsentLogic.buildConsentRequestConstructedEvent has 7 return statements (exceeds 4 allowed).
              Open

              func (cl ConsentLogic) buildConsentRequestConstructedEvent(createConsentRequest *CreateConsentRequest) (*events.Event, error) {
                  var err error
                  var consentID string
                  var records []bridgeClient.ConsentRecord
                  legalEntities := []bridgeClient.Identifier{
              Severity: Major
              Found in pkg/logic.go - About 45 mins to fix

                Method ConsentLogic.HandleEventConsentDistributed has 6 return statements (exceeds 4 allowed).
                Open

                func (cl ConsentLogic) HandleEventConsentDistributed(event *events.Event) {
                    crs := bridgeClient.ConsentState{}
                    decodedPayload, err := base64.StdEncoding.DecodeString(event.Payload)
                    if err != nil {
                        logger().Errorf("Unable to base64 decode event payload")
                Severity: Major
                Found in pkg/logic.go - About 40 mins to fix

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

                  func NewConsentLogicInstance(config ConsentLogicConfig, cryptoClient crypto.Client, registryClient pkg.RegistryClient, consentStoreClient cStore.ConsentStoreClient, eventOctopusClient events.EventOctopusClient) *ConsentLogic {
                  Severity: Minor
                  Found in pkg/logic.go - About 35 mins to fix

                    Method ConsentLogic.decryptConsentRecord has 5 return statements (exceeds 4 allowed).
                    Open

                    func (cl ConsentLogic) decryptConsentRecord(cr bridgeClient.ConsentRecord, legalEntity string) (string, error) {
                        encodedCipherText := cr.CipherText
                        cipherText, err := base64.StdEncoding.DecodeString(*encodedCipherText)
                        // convert hex string of attachment to bytes
                        if err != nil {
                    Severity: Major
                    Found in pkg/logic.go - About 35 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status