Refactor: Reduce Cognitive Complexity Reported by SonarQube on NF Discovery - #374
Merged
Merged
Conversation
Signed-off-by: ReshmaJS <you@example.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the NF Discovery implementation to reduce cognitive complexity (per SonarQube) by extracting validation and filter-building logic into smaller helper functions, aiming to improve maintainability without changing discovery behavior.
Changes:
- Extracted complexQuery validation into
validateComplexQuery. - Extracted profile sorting/decoding/fallback into
sortNFProfiles, and BSF IP conversion intohandleBSFIpConversion. - Refactored
buildFilterinto many focusedhandle*helper functions.
Suppressed comments (2)
producer/nf_discovery.go:1792
- handleComplexQuery indexes queryParameters["complexQuery"][0] after only checking for nil. If the key exists with an empty (non-nil) slice, this panics. Use a length check before indexing.
if queryParameters["complexQuery"] != nil {
// translate raw data to complexQuery structure
complexQuery := queryParameters["complexQuery"][0]
complexQueryStruct := &models.ComplexQuery{}
producer/nf_discovery.go:1798
- The local variable name
complexQueryFilteris the same as the functioncomplexQueryFilter(...), which is easy to misread and makes debugging harder. Rename the variable to avoid shadowing/confusion.
complexQueryFilter := complexQueryFilter(complexQueryStruct)
filter["$and"] = append(filter["$and"].([]bson.M), complexQueryFilter)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 2 commits
August 5, 2026 17:22
Signed-off-by: ReshmaJS <you@example.com>
gab-arrobo
approved these changes
Aug 5, 2026
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the code to reduce cognitive complexity, improving maintainability and ensuring compliance with static analysis rules.