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

Refactor Generators #4055

Closed

Conversation

mostafakhudair
Copy link
Contributor

@mostafakhudair mostafakhudair commented Jan 2, 2021

Refactor generators commands to match with standard commands with additional useful options

All generators extends BaseCommand using GeneratorTrait
Fix Controller extends PresenterController methods
Auto generate Entity class on make:model with option -return entity
for example:
php spark make:model users -table users -return entity
will result
App\Models\Users
App\Entities\Users

Add suffix class name by prepend component name, with --suffix option
for example:
php spark make:controller users
will result
App\Controllers\Users

php spark make:controller users
will result
App\Controllers\UsersController

Scaffold command removed for now and will be added in a separate PR later

Simplify code and clean unnecessary vars

userguide will be updated in a separated PR

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@MGatner
Copy link
Member

MGatner commented Jan 2, 2021

This looks like a good move, but I will need to review it more thoroughly on desktop. Also looks like some static analysis failures, so maybe WIP? We would need to have this done before release in order to avoid breaking changes on the generator class names.

@mostafakhudair
Copy link
Contributor Author

Thanks @MGatner , and I'm working on it, I hope if i finish it today

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I like the refactors made. I'll do a full review tomorrow but my initial concern is on programmatic calls. CLI::getOption() will return nothing when the command is not called via cli, that is why we need to check array_key_exists on the $params. This way, the options can be tested via unit tests. So, please do not remove those array_key_exists checks already in place.

Another one is on the --force option handling. This option is meant to allow overwriting files but you made it impossible to overwrite even if --force is given. It is like you are offering something and then when they grab that you refuse to give that right away. I find it quite illogical.

@mostafakhudair
Copy link
Contributor Author

file overwritten fine with --force option
I just put force check just after file is replaced
Screenshot from 2021-01-02 17-02-54

@paulbalandan
Copy link
Member

Alright, then. I maybe got quite confused with that block.

Please then re-include the access to $params for the options so it will be possible to use command('make:command foo --bare) and others programmatically. Also, please check the changes you've made to the unit tests and inquire why it runs "forever" and stuck at 4%. Maybe you inadvertently made a recursion error or something.

Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These review comments are not yet exhaustive but my initial comments only. Most of the comments are on the proper programmatic call handling.

system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/Commands/Generators/ScaffoldGenerator.php Outdated Show resolved Hide resolved
system/Commands/Generators/ScaffoldGenerator.php Outdated Show resolved Hide resolved
system/Commands/Generators/SessionMigrationGenerator.php Outdated Show resolved Hide resolved
system/Commands/Generators/SessionMigrationGenerator.php Outdated Show resolved Hide resolved
system/Commands/Generators/CommandGenerator.php Outdated Show resolved Hide resolved
@paulbalandan
Copy link
Member

I guess the 360 minute testing was caused by an executed call to CLI::prompt which keeps PHPUnit waiting for a keyboard input.

@mostafakhudair
Copy link
Contributor Author

@paulbalandan Thanks for this helpful review, give me few hours to be in home and i'll fix all of this mistakes

@MGatner
Copy link
Member

MGatner commented Jan 3, 2021

Nice work team! I came to see where this was at, I like seeing all the activity.

@mostafakhudair mostafakhudair force-pushed the refactor-generators branch 2 times, most recently from 7d27f64 to e669f5c Compare January 7, 2021 14:56
@mostafakhudair
Copy link
Contributor Author

CLI::promot is ignored now but phpunit still stuck, any help on this? @paulbalandan

@sfadschm
Copy link
Contributor

@mostafakhudair I ran the test locally one by one and indicated where looping happens. Seems to be related to the make:model command. Hope this helps.

@mostafakhudair
Copy link
Contributor Author

@sfadschm Thanks for your time to test this, but could you tell me why specially make:model looping

@mostafakhudair mostafakhudair force-pushed the refactor-generators branch 2 times, most recently from c85c09f to d40596e Compare January 13, 2021 19:48
@sfadschm
Copy link
Contributor

Btw. what happened to the model table defaulting to pluralized class name?

$table = $this->params['table'] ?? CLI::getOption('table');
if (! is_string($table))
{
$table = str_replace($this->getNamespace($class) . '\\', '', $class);
}
if ($pos = strripos($table, 'Model'))
{
$table = substr($table, 0, $pos);
}
// transform class name to lowercased plural for table name
$table = strtolower(plural($table));
return str_replace('{table}', $table, $template);

@mostafakhudair
Copy link
Contributor Author

Test ran well on local machine, but still stucked at 6% in here

@sfadschm
Copy link
Contributor

Thats still MigrationGeneratorTest. See comment somewhere above (kind of hard to follow the changes with all the force pushes :D).
So check the MigrationGenerator for required prompts and you should be fine.

@mostafakhudair
Copy link
Contributor Author

I already fixed model and migrate prompt before i push changes

@mostafakhudair mostafakhudair force-pushed the refactor-generators branch 2 times, most recently from 0d8b2c3 to f329f77 Compare January 15, 2021 15:41
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw a lot of comments here. Some are on the deviation from the original logic of GeneratorCommand, others on the design, while others is removing existing functionalities. I saw some changes removing existing functions even before GeneratorCommand was existing, so technically that removal is a BC break for existing users. I'll have to put the BC break tag until those BCs are resolved.

Also, don't dismiss right away a comment without providing an explanation. If you do not agree, tell us so.

system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
tests/_support/Commands/Foobar.php Outdated Show resolved Hide resolved
tests/_support/Commands/LanguageCommand.php Outdated Show resolved Hide resolved
tests/system/Commands/ConfigurableSortImportsTest.php Outdated Show resolved Hide resolved
tests/system/Commands/SessionsCommandsTest.php Outdated Show resolved Hide resolved
system/CLI/GeneratorTrait.php Outdated Show resolved Hide resolved
@paulbalandan paulbalandan added the breaking change Pull requests that may break existing functionalities label Jan 15, 2021
@mostafakhudair mostafakhudair mentioned this pull request Jan 17, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Pull requests that may break existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants