1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Allow Stringable in sprintf() values

This commit is contained in:
Rudolph Gottesheim 2023-09-26 08:51:21 +02:00
parent 83485f3fcf
commit aa04c0063b
2 changed files with 23 additions and 0 deletions

View File

@ -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()

View File

@ -125,6 +125,18 @@ class CoreStubsTest extends TestCase
'$a===' => 'string',
],
];
yield 'sprintf accepts Stringable values' => [
'code' => '<?php
$a = sprintf(
"%s",
new class implements Stringable { public function __toString(): string { return "hello"; } },
);
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0',
];
yield 'json_encode returns a non-empty-string provided JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE' => [
'code' => '<?php
$a = json_encode([], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);