From 48ab6dcb8cdd84ac44d94bd138aa3bf4702b963d Mon Sep 17 00:00:00 2001 From: phpstan-bot <79867460+phpstan-bot@users.noreply.github.com> Date: Sat, 24 Oct 2026 15:25:58 +0000 Subject: [PATCH] Accept `int` timeout and `null` for `$options` parameter of `Redis::set()` in function map - phpredis declares `Redis::set(string $key, mixed $value, mixed $options = null)`; `$options` may be an array of options, an int TTL in seconds (legacy form), or null. The function map narrowed it to `array`, causing false positives. - Compared every Redis/RedisCluster/RedisArray entry in functionMap.php against the native signatures of the loaded phpredis extension (null-default parameters and `mixed` options/timeout parameters); `Redis::set` was the only mismatch. --- resources/functionMap.php | 2 +- tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php | 8 ++++++++ tests/PHPStan/Rules/Methods/data/bug-15393.php | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-15393.php diff --git a/resources/functionMap.php b/resources/functionMap.php index 8e291259e0a..402720ffee8 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -8635,7 +8635,7 @@ 'Redis::sDiff' => ['__benevolent|false>', 'key'=>'string', '...other_keys='=>'string'], 'Redis::sDiffStore' => ['__benevolent', 'dst'=>'string', 'key'=>'string', '...other_keys='=>'string'], 'Redis::select' => ['__benevolent', 'db'=>'int'], -'Redis::set' => ['__benevolent', 'key'=>'string', 'value'=>'mixed', 'options='=>'array'], +'Redis::set' => ['__benevolent', 'key'=>'string', 'value'=>'mixed', 'options='=>'array|int|null'], 'Redis::setBit' => ['__benevolent', 'key'=>'string', 'idx'=>'int', 'value'=>'bool'], 'Redis::setex' => ['__benevolent', 'key'=>'string', 'expire'=>'int', 'value'=>'mixed'], 'Redis::setnx' => ['__benevolent', 'key'=>'string', 'value'=>'mixed'], diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index e03a97fc739..67834e4c54f 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -4586,4 +4586,12 @@ public function testClassConstantWildcardArguments(): void ]); } + public function testBug15393(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/data/bug-15393.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-15393.php b/tests/PHPStan/Rules/Methods/data/bug-15393.php new file mode 100644 index 00000000000..a4b74fb0ba5 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-15393.php @@ -0,0 +1,11 @@ +set('key', 'value'); + $redis->set('key', 'value', 3600); + $redis->set('key', 'value', ['nx', 'ex' => 3600]); + $redis->set('key', 'value', null); +}