File tree Expand file tree Collapse file tree
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,4 +54,48 @@ public function doitIf(array $items): void
5454 }, $ items );
5555 }
5656 }
57+
58+ /**
59+ * @param array<Foo|Bar> $items
60+ */
61+ public function doitMatchArrayUnion (array $ items ): void
62+ {
63+ if ([] === $ items ) {return ; }
64+
65+ $ first = reset ($ items );
66+ match (true ) {
67+ $ first instanceOf Foo => array_map (function ($ i ) {
68+ assertType ('Bug14201\Foo ' , $ i );
69+ return $ i ->fooName ;
70+ }, $ items ),
71+ $ first instanceOf Bar => array_map (function ($ i ) {
72+ assertType ('Bug14201\Bar ' , $ i );
73+ return $ i ->barName ;
74+ }, $ items ),
75+ default => throw new \RuntimeException ('None of Foo nor Bar ' )
76+ };
77+ }
78+
79+ /**
80+ * @param array<Foo|Bar> $items
81+ */
82+ public function doitIfArrayUnion (array $ items ): void
83+ {
84+ if ([] === $ items ) {return ; }
85+
86+ $ first = reset ($ items );
87+ if ($ first instanceof Foo) {
88+ assertType ('non-empty-array<Bug14201\Foo> ' , $ items );
89+ array_map (function ($ i ) {
90+ assertType ('Bug14201\Foo ' , $ i );
91+ return $ i ->fooName ;
92+ }, $ items );
93+ } elseif ($ first instanceof Bar) {
94+ assertType ('non-empty-array<Bug14201\Bar> ' , $ items );
95+ array_map (function ($ i ) {
96+ assertType ('Bug14201\Bar ' , $ i );
97+ return $ i ->barName ;
98+ }, $ items );
99+ }
100+ }
57101}
You can’t perform that action at this time.
0 commit comments