Selection::where() and other methods “: static” return type
- Antarian
- Member | 2
Just curious if anyone is having problem with code-completion suggestions for Selection class and what are possible ways to solve it.
PHPStorm not able to recognize return types of Selection class thanks to combination of “: static” and PHPStan annotation for “@return static<T>” template. I don't think they will fix it anytime soon (it is there 5+ years), as it is not that often you encounter this style/combination of code.
This is really hindering productivity as code completion suggetions for DB methods are non existent. It may not be a problem for people using only nette/database. But I am working with 4 other DB systems (Yii, Eloquent, Doctrine and one custom) and it is slow to always look for class structure to get methods.
Is there a reason why methods in Selection class are returning “: static” instead of “: self”? I suspect that this is because of child class.
Or why there is no interface to follow for the methods of this class. That may be used as return type in Selection class.
Or at least it will allow to create reliable decorator classes for Explorer and Selection in my project.
Is there any other way how to get code-completion suggestions?
Last edited by Antarian (2025-02-23 10:35)
- Marek Bartoš
- Nette Blogger | 1297
That should be reported as a PHPStorm bug, static instead of self should work just fine and it is the correct type to use there.
- David Grudl
- Nette Core | 8253
What specific code is not working for you? I'm using PhpPStorm, and the autocomplete for NDB works great.
- Marek Bartoš
- Nette Blogger | 1297
@DavidGrudl This is a minimal issue reproduction I was able to create
with latest PHPStorm. After the second where()
call, IDE just
forgets the type and provides no autocomplete. With native return type
self
instead of static
it works just fine.
- Marek Bartoš
- Nette Blogger | 1297
Same problem. First two methods work, third one does not.
Simplest workaround for now would be making the static
phpdoc
type phpstan-only to make sure type-completion works.
Generics are simply broken in PHPStorm. Even simple ones like the one in
Container->getByType()
doesn't work for me on some projects.
Last edited by Marek Bartoš (2025-02-24 16:13)