♻️ Refactor Ctx.Method func to improve code readability #2647
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.
Description
I've simplified the function by breaking it down into three trivially simple steps:
Step One: We check if no arguments are provided in the
override
parameter, in which case we have no choice but to returnc.method
. If arguments are provided, we proceed to step two.Step Two: We take the first string from
override
and validate if it's a valid HTTP Method name. If it's not, it's evident that we need to return the current method from the context. If it is valid, we move on to step three.Now, in step three, we have a valid HTTP Method in the
override
parameter. We save this method and its code to the context and return the method's name as a string.This pull request doesn't fix any bugs, but it improves the code's readability.
I decided to submit these changes because my younger sister (a budding programmer with a diagnosis of semantic dyslexia) asked me to explain what this function does, and I had to put in some effort to understand what was happening and explain to her that two consecutive 'if' statements are better than two nested ones. 🧡
Type of change
Checklist:
Commit formatting:
Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/
🎨