Skip to content

Commit

Permalink
Merge pull request #7967 from hirokinoue/fix_return_type
Browse files Browse the repository at this point in the history
Improve @return annotation for implode() so that it can handle non-empty-array of non-empty-strings case
  • Loading branch information
orklah committed May 17, 2022
2 parents 3929d73 + 4fc34d9 commit 894e4e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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

0 comments on commit 894e4e4

Please sign in to comment.