File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,13 +42,26 @@ public static function boolean(callable $filter): void
4242 $ separator = $ returnType instanceof ReflectionUnionType ? '| ' : '& ' ;
4343 $ types = $ returnType ->getTypes ();
4444
45- Assert::allIsInstanceOf ($ types , ReflectionNamedType::class);
45+ Assert::allIsInstanceOfAny ($ types , [ ReflectionNamedType::class, ReflectionIntersectionType::class] );
4646
4747 throw new InvalidArgumentException (
4848 sprintf (
4949 self ::MESSAGE ,
5050 implode ($ separator , array_map (
51- static fn (ReflectionNamedType $ reflectionNamedType ): string => $ reflectionNamedType ->getName (),
51+ function (ReflectionNamedType |ReflectionIntersectionType $ reflectionType ): string {
52+ if ($ reflectionType instanceof ReflectionNamedType) {
53+ return $ reflectionType ->getName ();
54+ }
55+
56+ $ subTypes = $ reflectionType ->getTypes ();
57+ Assert::allIsInstanceOf ($ subTypes , ReflectionNamedType::class);
58+
59+ return '( ' . implode ('& ' , array_map (
60+ static fn (ReflectionNamedType $ reflectionNamedType ): string
61+ => $ reflectionNamedType ->getName (),
62+ $ subTypes
63+ )) . ') ' ;
64+ },
5265 $ types
5366 ))
5467 )
Original file line number Diff line number Diff line change @@ -133,4 +133,21 @@ public function __invoke(int $datum): A&B
133133
134134 AtLeast::once ($ data , $ filter );
135135 }
136+
137+ public function testWithUnionedIntersectionTypeCallable (): void
138+ {
139+ $ this ->expectException (InvalidArgumentException::class);
140+ $ this ->expectExceptionMessage (
141+ 'Expected a bool return type on callable filter, (ArrayLookup\Tests\A&ArrayLookup\Tests\B)|string given '
142+ );
143+
144+ $ data = [1 , 2 , 3 ];
145+ $ filter = new class {
146+ public function __invoke (int $ datum ): (A &B )|string
147+ {
148+ }
149+ };
150+
151+ AtLeast::once ($ data , $ filter );
152+ }
136153}
You can’t perform that action at this time.
0 commit comments