Skip to content

Refactor: Reduce Cognitive Complexity Reported by SonarQube on NF Discovery - #374

Merged
gab-arrobo merged 4 commits into
omec-project:mainfrom
ReshmaJS:sq_nfdiscovery_pending
Aug 5, 2026
Merged

Refactor: Reduce Cognitive Complexity Reported by SonarQube on NF Discovery#374
gab-arrobo merged 4 commits into
omec-project:mainfrom
ReshmaJS:sq_nfdiscovery_pending

Conversation

@ReshmaJS

@ReshmaJS ReshmaJS commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This PR refactors the code to reduce cognitive complexity, improving maintainability and ensuring compliance with static analysis rules.

Signed-off-by: ReshmaJS <you@example.com>
@ReshmaJS
ReshmaJS requested a review from a team August 3, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into handleBSFIpConversion.
  • Refactored buildFilter into many focused handle* 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 complexQueryFilter is the same as the function complexQueryFilter(...), 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.

Comment thread producer/nf_discovery.go Outdated
Comment thread producer/nf_discovery.go Outdated
Comment thread producer/nf_discovery.go Outdated
ReshmaJS added 2 commits August 5, 2026 17:22
Signed-off-by: ReshmaJS <you@example.com>
@gab-arrobo
gab-arrobo merged commit e0eb062 into omec-project:main Aug 5, 2026
12 checks passed
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.

3 participants