Fixed code smell in src/user/email.js: reduced complexity of function 'validateEmail'#317
Open
aaronlockhartdev wants to merge 1 commit into
Open
Fixed code smell in src/user/email.js: reduced complexity of function 'validateEmail'#317aaronlockhartdev wants to merge 1 commit into
aaronlockhartdev wants to merge 1 commit into
Conversation
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.
Refactor: Reduce complexity of sendValidationEmail function
Changes
Refactored the
UserEmail.sendValidationEmailfunction to reduce cyclomatic complexity from 10 to 4, addressing a Qlty code smell report.Problem
The
sendValidationEmailfunction had high complexity due to multiple nested conditionals and responsibility handling within a single function, making it harder to understand, test, and maintain.Solution
Extracted four helper functions, each handling a single responsibility:
_normalizeOptions: Normalizes and validates the options parameter, handles backward compatibility with string arguments, and retrieves email from uid if not provided_prepareConfirmationData: Prepares the confirmation data and fires filter hooks for extensibility_persistConfirmationData: Handles all database operations for storing confirmation data_sendEmail: Manages logging and sends the confirmation email via emailer or action hooksThe main
sendValidationEmailfunction now has a clean, linear flow that clearly shows the validation and processing steps.Benefits
Files Modified
src/user/email.jsTesting
All existing functionality is preserved. The refactoring maintains backward compatibility with existing callers of
sendValidationEmail.