File tree Expand file tree Collapse file tree 1 file changed +36
-11
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 1 file changed +36
-11
lines changed Original file line number Diff line number Diff line change 22
33namespace Bug4090 ;
44
5+ use function current ;
56use 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}
You can’t perform that action at this time.
0 commit comments