php-resque
php-resque copied to clipboard
feat: update PHPStan lvl to 5
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.
Updated based on the latest state of the develop branch.
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.
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
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.
$instancecan 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.
Add
|nulland it should sort itself.
Yeah, I had that until https://github.com/resque/php-resque/pull/91#discussion_r1998757553
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.
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.
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.