Skip to content

Commit 3affe77

Browse files
committed
Regression test
Closes phpstan/phpstan#10438
1 parent f880231 commit 3affe77

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10438;
4+
5+
use SimpleXMLElement;
6+
use function PHPStan\Testing\assertType;
7+
8+
class HelloWorld
9+
{
10+
/**
11+
* @return array<string, string|string[]>
12+
*/
13+
public function extract(SimpleXMLElement $data, string $type = 'Meta'): array
14+
{
15+
$keyName = ucfirst($type) . 'Type';
16+
$valueName = ucfirst($type) . 'Values';
17+
$meta = [];
18+
foreach ($data as $tag) {
19+
$key = (string)$tag->{$keyName};
20+
if ($tag->{$valueName}->count() == 1) {
21+
$meta[$key] = (string)$tag->{$valueName};
22+
continue;
23+
}
24+
assertType('array<string, list<string>|string>', $meta);
25+
$meta[$key] = [];
26+
assertType('array{}', $meta[$key]);
27+
foreach ($tag->{$valueName} as $value) {
28+
assertType('list<string>', $meta[$key]);
29+
$meta[$key][] = (string)$value;
30+
}
31+
}
32+
return $meta;
33+
}
34+
}

0 commit comments

Comments
 (0)