Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve @return annotation for implode() so that it can handle non-empty-array of non-empty-strings case #7967

Merged
merged 3 commits into from May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions stubs/CoreGenericFunctions.phpstub
Expand Up @@ -582,7 +582,12 @@ function rtrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
* : non-empty-string
* )
* : string)
* : string
* : ($array is non-empty-array
* ? ($array is array<non-empty-literal-string|non-empty-string>
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
* : string
* )
* : string)
* )
*
* @psalm-flow ($separator) -> return
Expand All @@ -604,7 +609,12 @@ function implode($separator, array $array = []) : string {}
* : non-empty-string
* )
* : string)
* : string
* : ($array is non-empty-array
* ? ($array is array<non-empty-literal-string|non-empty-string>
* ? ($array is array<non-empty-literal-string> ? non-empty-literal-string : non-empty-string)
* : string
* )
* : string)
* )
*
* @psalm-flow ($separator) -> return
Expand Down
25 changes: 25 additions & 0 deletions tests/ArrayFunctionCallTest.php
Expand Up @@ -1055,6 +1055,31 @@ function mapdef(string $_a, int $_b = 0): string {
'$b===' => 'non-empty-literal-string',
]
],
'implodeArrayOfNonEmptyStringAndEmptyString' => [
'<?php
class Foo {
const DIR = __DIR__;
}
$l = ["a", "b"];
$k = [Foo::DIR];
$a = implode("", $l);
$b = implode("", $k);',
[
'$a===' => 'non-empty-literal-string',
'$b===' => 'non-empty-string',
]
],
'implodeEmptyArrayAndString' => [
'<?php
$l = [""];
$k = [];
$a = implode("", $l);
$b = implode("", $k);',
[
'$a===' => 'string',
'$b===' => 'string',
]
],
'key' => [
'<?php
$a = ["one" => 1, "two" => 3];
Expand Down