FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: reduce cognitive complexity flagged by SonarCloud by osanderson · Pull Request #200 · IDFoundry/FAPIgo · GitHub

refactor: reduce cognitive complexity flagged by SonarCloud - #200

Merged
osanderson merged 1 commit into
mainfrom
refactor/cognitive-complexity
Aug 29, 2026
Merged

refactor: reduce cognitive complexity flagged by SonarCloud#200
osanderson merged 1 commit into
mainfrom
refactor/cognitive-complexity

Conversation

Copy link
Copy Markdown
Collaborator

Summary

Addresses 11 of the 29 open go:S3776 (Cognitive Complexity) issues on SonarCloud, via pure mechanical extraction with no behavior change:

  • storage/contract.go: extract every t.Run closure body in TestGrantStoreContract/TestAccessTokenStoreContract/TestBackchannelAuthenticationStoreContract into standalone top-level functions — mirrors the Transaction/Session/Nonce contracts already fixed this way in an earlier PR.
  • cmd/conformance-as/config.go: extract resolveClient's three independent string→enum switches into their own parseXxx helpers.
  • internal/jose/jwk.go: extract ParseJWK's EC/RSA/OKP cases into their own parse*PublicKey functions.
  • keys/publicjwks.go: extract the "validate kid, dedup, build, append" tail duplicated verbatim across PublicJWKS's signing and encryption loops into a shared appendPublicJWK helper.
  • resource/verify.go: extract Verify's DPoP/Bearer credential-resolution switch into its own resolveCredential method.
  • client/backchannel.go: extract the client-assertion/DPoP signer-resolution block duplicated across BeginBackchannelAuthentication/PollBackchannelAuthentication into a shared resolveClientAuthAndDPoPSigners helper.
  • client/flow_test.go: extract fakeAS.handleToken's three response-mode branches into their own methods.

The remaining 18 issues are flat validation/checklist functions (e.g. client/client.go, server/server.go, storage/client_repository.go constructors) or large sequential test/harness setups where splitting would just scatter one audit-worthy list across files without improving readability — left as-is per this repo's own "don't refactor for a linter number alone" convention. server/token.go's ExchangeAuthorizationCode was specifically investigated for duplication and found to already reuse shared helpers (issueIDToken, issueRefreshToken, withIdentityClaims, withRequestedUserinfoClaims) with refresh.go/backchannel_token.go — nothing left to extract there.

Test plan

  • go build ./... && go vet ./... && gofmt -l . clean
  • go test ./... passes after every individual extraction and at the end

🤖 Generated with Claude Code

https://claude.ai/code/session_013tGG2Ssuq5BDgCMbF8zYb8

Mechanical extraction, no behavior change, addressing 11 of the 29
open go:S3776 issues (the other 18 are flat validation/checklist
functions or large sequential test setups where splitting would just
scatter the same logic across files for no readability gain):

- storage/contract.go: extract every t.Run closure body in
  TestGrantStoreContract/TestAccessTokenStoreContract/
  TestBackchannelAuthenticationStoreContract into standalone top-level
  functions, mirroring the Transaction/Session/Nonce contracts already
  fixed this way.
- cmd/conformance-as/config.go: extract resolveClient's three
  independent string-to-enum switches (client_auth_method,
  sender_constrain, backchannel_token_delivery_mode) into their own
  parseXxx helpers.
- internal/jose/jwk.go: extract ParseJWK's EC/RSA/OKP cases into their
  own parse*PublicKey functions.
- keys/publicjwks.go: extract the "validate kid, dedup, build, append"
  tail PublicJWKS's signing and encryption loops both duplicated
  verbatim into a shared appendPublicJWK helper.
- resource/verify.go: extract Verify's DPoP/Bearer credential
  -resolution switch into its own resolveCredential method.
- client/backchannel.go: extract the client-assertion/DPoP signer
  -resolution block BeginBackchannelAuthentication and
  PollBackchannelAuthentication both duplicated into a shared
  resolveClientAuthAndDPoPSigners helper.
- client/flow_test.go: extract fakeAS.handleToken's three response
  -mode branches (reject-plain, nonce-challenge, normal-issue) into
  their own methods.

server/token.go's ExchangeAuthorizationCode was investigated and left
unchanged: its token-issuance tail already calls the same shared
helpers (issueIDToken, issueRefreshToken, withIdentityClaims,
withRequestedUserinfoClaims) that refresh.go and backchannel_token.go
reuse — no duplication left to extract, and the remaining complexity
is a flat validation checklist.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copy link
Copy Markdown

osanderson merged commit b43aae8 into main Aug 29, 2026
8 checks passed
osanderson deleted the refactor/cognitive-complexity branch August 29, 2026 09:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL