[7.x] Disallow generation commands with reserved names #33037
Merged
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.
What
This PR makes it so that an error is displayed to the user when they attempt to use a reserved keyword in a generator command. For example:
Why
Using PHP keywords as the name when using generation commands is not only bad practice, but it simply does not even work.
In my situation I wanted to create a model called
Case
(in the context of a "crime case").This will not work. A context sensitive lexer was added in PHP 7, which allows you to use reserved keywords in method names. However, this does not go for class names.
Some could say:
I partially agree, but when you use the following generation command for example:
It will successfully create a model class, factory, migration, seeder, and then... oops:
And now your project is polluted with a model class, factory, migration and seeder, while the model isn't usable in the first place. It would be much better to disallow the scaffolding immediately and prevent this.
Screenshot
The error that is displayed when attempting to scaffold with a reserved name.