Skip to content
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

[7.x] Disallow generation commands with reserved names #33037

Merged
merged 2 commits into from
Jun 1, 2020
Merged

[7.x] Disallow generation commands with reserved names #33037

merged 2 commits into from
Jun 1, 2020

Conversation

musa11971
Copy link
Contributor

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:

php artisan make:model Case

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:

"Developers should just be cautious and not use keywords when scaffolding."

I partially agree, but when you use the following generation command for example:

php artisan make:model Case -a

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.

@musa11971 musa11971 changed the title Disallow generation commands with reserved names [7.x] Disallow generation commands with reserved names May 31, 2020
@anouarabdsslm
Copy link
Contributor

@musa11971 you may need to add a test

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