File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments