vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.58k stars 664 forks source link

RedisCluster::setOption() argument types incorrect #4708

Closed jaikdean closed 3 years ago

jaikdean commented 4 years ago

This example has been written as per the documentation for RedisCluster::setOption(). It may be that the constants or method signatures in the Redis extension have changed over time, but it's certainly throwing errors on the latest version.

psalm-github-bot[bot] commented 4 years ago

I found these snippets:

https://psalm.dev/r/773bc62f21 ```php setOption(\RedisCluster::OPT_SLAVE_FAILOVER, \RedisCluster::FAILOVER_NONE); ``` ``` Psalm output (using commit 01ceaf7): ERROR: InvalidScalarArgument - 4:21 - Argument 1 of RedisCluster::setoption expects string, int(5) provided ERROR: InvalidScalarArgument - 4:56 - Argument 2 of RedisCluster::setoption expects string, int(0) provided ```
orklah commented 4 years ago

Could you try to dump the value of \RedisCluster::FAILOVER_NONE to see if it's a string that has been flagged as an int or if it's indeed an int and we should change the method signature?

jaikdean commented 4 years ago

Looks like it's an int.

$ php -v
PHP 7.4.12 (cli) (built: Oct 29 2020 18:37:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
    with Zend OPcache v7.4.12, Copyright (c), by Zend Technologies
$ php -i | grep "Redis Version"
Redis Version => 5.3.1
$ php -r 'var_dump(\RedisCluster::FAILOVER_NONE);'
Command line code:1:
int(0)
orklah commented 4 years ago

Thanks :)

Then it should be a simple change in this file: https://github.com/vimeo/psalm/blob/master/dictionaries/CallMap.php on the line with Rediscluster::setOption

We should add int to the types accepted for param value.

Do you want to try pushing a PR?