1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Merge pull request #7967 from hirokinoue/fix_return_type

Improve @return annotation for implode() so that it can handle non-empty-array of non-empty-strings case
This commit is contained in:
orklah 2022-05-17 20:54:58 +02:00 committed by GitHub
commit 894e4e4c02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

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

View File

@ -1055,6 +1055,31 @@ class ArrayFunctionCallTest extends TestCase
'$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];