From 987981b12a64049f99a167796460627a7de6498b Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Sun, 18 Dec 2022 15:12:49 +0600 Subject: [PATCH 1/5] Make sprintf return non-empty-string when arguments non-empty-strings too --- stubs/CoreGenericFunctions.phpstub | 8 +++++++- tests/CoreStubsTest.php | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index 4ce4136f01e..8aeae1df060 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -1116,7 +1116,13 @@ function preg_quote(string $str, ?string $delimiter = null) : string {} /** * @psalm-pure * - * @param string|int|float $values + * @template TFormat of string + * @template TVal of string|int|float + * @param TFormat $format + * @param TVal $values + * @return (TFormat is non-empty-string + * ? (TVal is non-empty-string|int|float ? non-empty-string : string) + * : string) * * @psalm-flow ($format, $values) -> return */ diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index 3d76a0d343a..d25c27de7d3 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -101,5 +101,18 @@ public function providerValidCodeParse(): iterable 'ignored_issues' => ['RedundantCondition'], 'php_version' => '8.0', ]; + yield 'sprintf yields a non-empty-string' => [ + ' Date: Sun, 18 Dec 2022 15:55:48 +0600 Subject: [PATCH 2/5] Remove no longer necessary @vars --- tests/Config/ConfigTest.php | 1 - tests/Config/PluginTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 65d3a3845f5..0c1645e5889 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -1461,7 +1461,6 @@ public function pluginRegistersScannerAndAnalyzer(int $flags, ?int $expectedExce FileTypeSelfRegisteringPlugin::$names = $names; FileTypeSelfRegisteringPlugin::$flags = $flags; - /** @var non-empty-string $xml */ $xml = sprintf( ' ', diff --git a/tests/Config/PluginTest.php b/tests/Config/PluginTest.php index 62319390e9b..7bb95644a47 100644 --- a/tests/Config/PluginTest.php +++ b/tests/Config/PluginTest.php @@ -801,7 +801,6 @@ public function testAfterAnalysisHooks(): void public function testPluginFilenameCanBeAbsolute(): void { - /** @var non-empty-string $xml */ $xml = sprintf( ' expectException(InvalidArgumentException::class); $this->expectExceptionMessage('does-not-exist/plugins/StringChecker.php'); - /** @var non-empty-string $xml */ $xml = sprintf( ' Date: Sun, 18 Dec 2022 16:04:16 +0600 Subject: [PATCH 3/5] Add one more test --- tests/CoreStubsTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index d25c27de7d3..a0f2bfd282d 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -101,7 +101,7 @@ public function providerValidCodeParse(): iterable 'ignored_issues' => ['RedundantCondition'], 'php_version' => '8.0', ]; - yield 'sprintf yields a non-empty-string' => [ + yield 'sprintf yields a non-empty-string for non-empty-string value' => [ ' [ + ' [ + '$a===' => 'string', + ] + ]; } } From dd76a1e48136b06ae759294deb0a4609280cc3ff Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Sun, 18 Dec 2022 16:26:43 +0600 Subject: [PATCH 4/5] Fix tests --- tests/CoreStubsTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index a0f2bfd282d..d1149f1b38a 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -102,7 +102,7 @@ public function providerValidCodeParse(): iterable 'php_version' => '8.0', ]; yield 'sprintf yields a non-empty-string for non-empty-string value' => [ - ' ' [ - ' ' [ '$a===' => 'string', - ] + ], ]; } } From 9a22d682f54a5c062347b102320b7da1b403b188 Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Sun, 18 Dec 2022 17:13:39 +0600 Subject: [PATCH 5/5] Simplify conditional return --- stubs/CoreGenericFunctions.phpstub | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index 8aeae1df060..a8399e9e53e 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -1116,12 +1116,9 @@ function preg_quote(string $str, ?string $delimiter = null) : string {} /** * @psalm-pure * - * @template TFormat of string - * @template TVal of string|int|float - * @param TFormat $format - * @param TVal $values - * @return (TFormat is non-empty-string - * ? (TVal is non-empty-string|int|float ? non-empty-string : string) + * @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