-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update getBehavior annotation to allow better code analyse on applica… #18323
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
Update getBehavior annotation to allow better code analyse on applica… #18323
Conversation
At model I've used |
Using |
For PHPStorm the IdeHelper and meta file helps. |
Pretty much all popular stan tools and IDEs understand annotation template vars. So using un-prefixed annotations is fine. Also for consistency |
We already have multiple use of |
This is the first indirect case (trick for getBehavior). |
|
Please let me know if we should use phpstan- prefix |
Not for template, and for the others also not if it doesnt work any other way. |
At PHP Storm both ways have the same behavior. It can't autcomplete methods from concrete behavior class only from \Cake\ORM\Behavior. |
PHPStorm can itself also autocomplete, through the meta file, thats a PHPStorm internal separate topic. at least that works for sure, if we keep the old param/return. So right now "working" I mean the new PHPStan introspection, that ideally works with prefixed param/return then. |
Updated. Tested at localhost with phpstan and tag generated with cakephp-ide-helper. |
OK, I needed to run phpstan with --debug to clear the cache
Just fine for me I also verified that PHPStorm still can autocomplete through meta file, also works
Takes care of that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably silence the psalm issue.
Or add a psalm-* tag on top that specifically sets it for psalm to the expected behavior.
psalm tests passed with |
dereuromark/cakephp-ide-helper#374 It would by default add the annotations only for 5.2.2+ (since before it would throw errors) |
* @template TName of key-of<TBehaviors> | ||
* @phpstan-param TName $name The behavior alias to get from the registry. | ||
* @phpstan-return TBehaviors[TName] | ||
* @psalm-return \Cake\ORM\Behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
psalm-return looks the same as return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but see the commits above. If not added on top, psalm goes all ballistic on us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because psalm reads @phpstan-
prefixed annotations too (and vice versa) and it doesn't understand TBehaviors[TName]
, hence @psalm-return
is also required to override the @phpstan-return
.
Related to CakeDC/cakephp-phpstan#44 and #18318
Add annotation to improve static analyse.
Application models will be able to use a phpdoc to set possible return types for Table::getBehavior