From aa04c0063bb3e2e8dc39a44cd10d8443e1b4435e Mon Sep 17 00:00:00 2001 From: Rudolph Gottesheim Date: Tue, 26 Sep 2023 08:51:21 +0200 Subject: [PATCH] Allow Stringable in sprintf() values --- stubs/Php80.phpstub | 11 +++++++++++ tests/CoreStubsTest.php | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/stubs/Php80.phpstub b/stubs/Php80.phpstub index 2f2d5bf0b..9a70506d9 100644 --- a/stubs/Php80.phpstub +++ b/stubs/Php80.phpstub @@ -247,6 +247,17 @@ function get_headers(string $url, bool $associative = false, $context = null) : */ function pack(string $format, mixed ...$values): string {} +/** + * @psalm-pure + * + * @param string|Stringable|int|float $values + * @return (PHP_MAJOR_VERSION is 8 ? string : string|false) + * @psalm-ignore-falsable-return + * + * @psalm-flow ($format, $values) -> return + */ +function sprintf(string $format, ...$values) {} + final class CurlHandle { private function __construct() diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index ed3d0b763..b01898970 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -125,6 +125,18 @@ class CoreStubsTest extends TestCase '$a===' => 'string', ], ]; + yield 'sprintf accepts Stringable values' => [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.0', + ]; yield 'json_encode returns a non-empty-string provided JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE' => [ 'code' => '