gen:model: Modifying Getter, Setting, and IDE code generation issues #6137
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.
ModelRewriteGetterSetterVisitor问题:
其中getter和setter是从当前model代码(AST)中获取的,没有考虑父类和trait等,重写方法可能会导致错误,例如
PHP Fatal error: Declaration of App\Model\User::setCreatedAt($created_at) must be compatible with Hyperf\Database\Model\Model::setCreatedAt($value): static in /project/hyperf-skeleton/app/Model/User.php on line 104
GenerateModelIDEVisitor问题:
Model中的方法是从最新model代码(AST)中获取的,是用其中方法名去反射获取方法可能会导致方法不存在的错误(model类已经在内存中加载,最最新的代码没有适用),例如一下命令·php bin/hyperf.php gen:model user --with-ide·,第一次ide会生成失败,再一次执行就可以成功了(第二次重新加载了代码,是最新的)