Skip to content

Commit 1c5ab45

Browse files
committed
Update bug-4090.php
1 parent 0435f0e commit 1c5ab45

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

tests/PHPStan/Analyser/nsrt/bug-4090.php

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,46 @@
22

33
namespace Bug4090;
44

5+
use function current;
56
use function PHPStan\Testing\assertType;
67

7-
class HelloWorld
8+
/** @param string[] $a */
9+
function foo(array $a): void
810
{
11+
if (count($a) > 1) {
12+
echo implode(',', $a);
13+
} elseif (count($a) === 1) {
14+
assertType('string', current($a));
15+
echo trim(current($a));
16+
}
17+
}
918

10-
/**
11-
* @param string[] $items
12-
*/
13-
public function test(string $value, array $items): void
14-
{
15-
if (in_array($value, $items, true)) {
16-
assertType('non-empty-array<string>', $items);
17-
$first = current($items);
18-
assertType('string', $first);
19-
}
19+
20+
/** @param string[] $a */
21+
function bar(array $a): void
22+
{
23+
$count = count($a);
24+
if ($count > 1) {
25+
echo implode(',', $a);
26+
} elseif ($count === 1) {
27+
assertType('string', current($a));
28+
echo trim(current($a));
2029
}
30+
}
31+
2132

33+
/** @param string[] $a */
34+
function qux(array $a): void
35+
{
36+
switch (count($a)) {
37+
case 0:
38+
break;
39+
case 1:
40+
assertType('string', current($a));
41+
echo trim(current($a));
42+
break;
43+
default:
44+
echo implode(',', $a);
45+
break;
46+
}
2247
}

0 commit comments

Comments
 (0)