itsgoingd / clockwork

Clockwork - php dev tools in your browser - server-side component
https://underground.works/clockwork
MIT License
5.69k stars 321 forks source link

Update PHPDoc for the helper `clock` to add return type #702

Open alies-dev opened 6 months ago

alies-dev commented 6 months ago

Add PHPDoc to help static analysers (incl. IDE)

image

(on this screenshot PHPStorm understands that clock() will return \Clockwork\Clockwork instance)

UlrichEckhardt commented 4 months ago

I like type annotations and this PR improves clockwork in that area.

itsgoingd commented 1 month ago

It would be cool, if instead of returning mixed, we could return the type of the first argument. I wonder if PHPStorm supports the @template syntax - https://psalm.dev/docs/annotating_code/templated_annotations/.

itsgoingd commented 1 month ago

So the good news is, we can probably write the PHPDoc in a way, where it always returns correct type instead of just mixed.

Bad news is, the conditional returns are currently broken in PHPStorm (https://youtrack.jetbrains.com/issue/WI-78351/Type-not-correctly-inferred-from-phpstan-psalm-conditional-generic-return-type), so I have to wait until they've fixed it, before I can experiment with it further.

alies-dev commented 1 month ago

Hey @itsgoingd It's great to see an activity on this thread! I would like to add that conditional returns work perfectly in PHPStan and Psalm, so I think there is still a value to add them