Replies: 1 comment 4 replies
-
You can use Rector to add return type to your code. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've noticed that, for example, larastan can only detect whether a model has a relationship if and only if the relationship-method in question explicitly returns the relationship type.
So for example:
Will not be automatically recognized. I would need to specifically write
function author(): BelongsTo
in order for larastan to understand it. Now I'm guessing this has something to do with that theReflection
methods aren't able to tell you what return type can be inferred from a function? I don't know. What I do know, is that barryvdh's laravel-ide-helper does seem to be able to decipher that these methods are relationships, even when they don't explicitly define a return-type.Now I know that barryvdh's laravel-ide-helper inspects the actual database structure and probably uses that to infer a lot of information that it otherwise couldn't.
But wouldn't it be awesome if larastan offered a similar feature? Either an executable binary in
vendor/bin
or an artisan command that alters all the model files to add better type annotations. Both in plain php (e.g.author(): BelongsTo
) and potentially in the docblocks above those methods if it's every relevant to add like generic types for example (e.g.@returns BelongsTo<static, User>
or whatever).Because as of now, I still see that barryvdh's laravel-ide-helper solves problems that larastan doesn't solve. But I think it would simply be amazing if larastan would solve all the problems that I currently need both packages for, so that in the future I'll only need one.
Beta Was this translation helpful? Give feedback.
All reactions