mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #8922 from fluffycondor/sprintf-non-empty-string
Make `sprintf` return `non-empty-string` when possible
This commit is contained in:
commit
7d95f15e30
@ -1117,6 +1117,9 @@ function preg_quote(string $str, ?string $delimiter = null) : string {}
|
||||
* @psalm-pure
|
||||
*
|
||||
* @param string|int|float $values
|
||||
* @return ($format is non-empty-string
|
||||
* ? ($values is non-empty-string|int|float ? non-empty-string : string)
|
||||
* : string)
|
||||
*
|
||||
* @psalm-flow ($format, $values) -> return
|
||||
*/
|
||||
|
@ -1461,7 +1461,6 @@ class ConfigTest extends TestCase
|
||||
FileTypeSelfRegisteringPlugin::$names = $names;
|
||||
FileTypeSelfRegisteringPlugin::$flags = $flags;
|
||||
|
||||
/** @var non-empty-string $xml */
|
||||
$xml = sprintf(
|
||||
'<?xml version="1.0"?>
|
||||
<psalm><plugins><pluginClass class="%s"/></plugins></psalm>',
|
||||
|
@ -801,7 +801,6 @@ class PluginTest extends TestCase
|
||||
|
||||
public function testPluginFilenameCanBeAbsolute(): void
|
||||
{
|
||||
/** @var non-empty-string $xml */
|
||||
$xml = sprintf(
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
@ -828,7 +827,6 @@ class PluginTest extends TestCase
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('does-not-exist/plugins/StringChecker.php');
|
||||
|
||||
/** @var non-empty-string $xml */
|
||||
$xml = sprintf(
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
|
@ -101,5 +101,27 @@ class CoreStubsTest extends TestCase
|
||||
'ignored_issues' => ['RedundantCondition'],
|
||||
'php_version' => '8.0',
|
||||
];
|
||||
yield 'sprintf yields a non-empty-string for non-empty-string value' => [
|
||||
'code' => '<?php
|
||||
|
||||
/**
|
||||
* @param non-empty-string $foo
|
||||
* @return non-empty-string
|
||||
*/
|
||||
function foo(string $foo): string
|
||||
{
|
||||
return sprintf("%s", $foo);
|
||||
}
|
||||
',
|
||||
];
|
||||
yield 'sprintf yields a string for possible empty string param' => [
|
||||
'code' => '<?php
|
||||
|
||||
$a = sprintf("%s", "");
|
||||
',
|
||||
'assertions' => [
|
||||
'$a===' => 'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user