clockwork icon indicating copy to clipboard operation
clockwork copied to clipboard

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

Open alies-dev opened this issue 1 year ago • 4 comments

Add PHPDoc to help static analysers (incl. IDE)

image

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

alies-dev avatar May 25 '24 11:05 alies-dev

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

UlrichEckhardt avatar Jun 30 '24 18:06 UlrichEckhardt

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 avatar Oct 14 '24 22:10 itsgoingd

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.

itsgoingd avatar Oct 20 '24 21:10 itsgoingd

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

alies-dev avatar Oct 21 '24 08:10 alies-dev