php-resque icon indicating copy to clipboard operation
php-resque copied to clipboard

feat: update PHPStan lvl to 5

Open SMillerDev opened this issue 9 months ago • 7 comments

This updates the PHPStan check to lvl 5. There are still some unresolved issues and the method types are based on the redis docs so might not be complete.

SMillerDev avatar Mar 05 '25 11:03 SMillerDev

Updated based on the latest state of the develop branch.

SMillerDev avatar Mar 17 '25 11:03 SMillerDev

For the one remaining failure, it looks like the documentation for blpop in Credis is incomplete. It does, in fact, allow an array input. https://github.com/colinmollenhour/credis/blob/v1.16.2/Client.php#L1670 will take the list of strings we pass in https://github.com/resque/php-resque/blob/develop/lib/Resque.php#L195 and make it a vararg essentially, so the signature is more like blpop(string $key1, string $key2, string $key3, ..., int $timeout), but that's obviously not supported by PHP.

I think adjusting that to string|string[] should be good enough.

pprkut avatar Mar 17 '25 13:03 pprkut

I won't stop you from pushing ahead here, but I feel like scope-creep is setting in :slightly_smiling_face: We don't need to push to level 5 directly, we can totally do intermediate steps which would keep the changes more manageable IMHO. But I leave that up to you

pprkut avatar Mar 17 '25 16:03 pprkut

I think it was mostly editing in the web UI that made it seem bad. I've covered everything now, except the fact that $instance can be unset but phpstan doesn't acknowledge that.

SMillerDev avatar Mar 18 '25 06:03 SMillerDev

$instance can be unset but phpstan doesn't acknowledge that.

With a type hint that doesn't include an uninitialized value as an option, it can't assume null is valid. Add |null and it should sort itself.

danhunsaker avatar Mar 18 '25 07:03 danhunsaker

Add |null and it should sort itself.

Yeah, I had that until https://github.com/resque/php-resque/pull/91#discussion_r1998757553

SMillerDev avatar Mar 18 '25 07:03 SMillerDev

I'll check it some more. Especially in newer PHP versions the assumption of "unitinitialized == null" is no longer true, that's why I don't think adding a type hint for it is correct. But maybe it's the simplest solution.

pprkut avatar Mar 18 '25 07:03 pprkut

A simpler solution would be to bump the project to php 7.4+ or even to a supported php version. Once the native type hint is added to the instance property phpstan stops complaining.

Redominus avatar Sep 04 '25 10:09 Redominus

Here is the needed changes to make phpstan accept the code. https://github.com/Redominus/php-resque/tree/feat/general/phpstan_4 I had to restrict credis version to 1.16.* as the newer versions have changed the cluster class constructor.

Redominus avatar Sep 04 '25 10:09 Redominus