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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config: display user-friendly message when invalid generator is passed #771
base: master
Are you sure you want to change the base?
Config: display user-friendly message when invalid generator is passed #771
Changes from 2 commits
3b6c8c6
6bb661d
541e2ef
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for making this property
static
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this property
static
because I see its value as common for all instances of this class and not something that will change depending on the instance of the class. Do you see other reasons not to make itstatic
?Anyway, I had to change it to an object property to be able to manipulate its value when generating the error message (copying the value of the property before manipulating it seemed too much). See #771 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
array_values()
really needed here ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wondering if for readability, the last comma should be replaced with " and " ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, no. It was added by mistake.
Yes, I think it is slightly better, and I used it in the original version. But then, when I moved to store the list of valid generators in a class property and used
implode()
to get the string with the name of the generators, I removed "and", assuming that the text is good enough without it, still correct and the code is slightly simpler.As you are asking, I'm assuming you prefer the version with the "and," so I went ahead and added it. I'm not super happy with my approach using
array_pop()
, but I couldn't think of anything better. Please let me know if you have another suggestion.Using
array_pop()
meant that I had to changeConfig::$validGenerators
to an object property instead of a class property which is related to another comment you left.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, but this is supposed to be an unchangeable array (to become a class constant later on as discussed in previous comments) and the use of
array_pop()
explicitly changes the array (by reference) and would block the future change to make this a class constant. See: https://3v4l.org/QrM61While the change of the property value would not currently be problematic (as a second
--generator=...
argument is ignored anyway), it does make the code less stable, so I'd like to see an alternative solution for this.