@@ -113,19 +113,17 @@ protected function getResult(): Type
113113 {
114114 $ isSuperType = $ this ->target ->isSuperTypeOf ($ this ->subject );
115115
116- $ yesType = fn () => TypeTraverser::map (!$ this ->negated ? $ this ->if : $ this ->else , function (Type $ type , callable $ traverse ) {
117- if ($ type ->equals ($ this ->subject )) {
118- return !$ this ->negated ? TypeCombinator::intersect ($ type , $ this ->target ) : TypeCombinator::remove ($ type , $ this ->target );
119- }
120- return $ traverse ($ type );
121- });
122-
123- $ noType = fn () => TypeTraverser::map (!$ this ->negated ? $ this ->else : $ this ->if , function (Type $ type , callable $ traverse ) {
124- if ($ type ->equals ($ this ->subject )) {
125- return !$ this ->negated ? TypeCombinator::remove ($ type , $ this ->target ) : TypeCombinator::intersect ($ type , $ this ->target );
126- }
127- return $ traverse ($ type );
128- });
116+ $ intersectedType = TypeCombinator::intersect ($ this ->subject , $ this ->target );
117+ $ removedType = TypeCombinator::remove ($ this ->subject , $ this ->target );
118+
119+ $ yesType = fn () => TypeTraverser::map (
120+ !$ this ->negated ? $ this ->if : $ this ->else ,
121+ fn (Type $ type , callable $ traverse ) => $ type === $ this ->subject ? (!$ this ->negated ? $ intersectedType : $ removedType ) : $ traverse ($ type ),
122+ );
123+ $ noType = fn () => TypeTraverser::map (
124+ !$ this ->negated ? $ this ->else : $ this ->if ,
125+ fn (Type $ type , callable $ traverse ) => $ type === $ this ->subject ? (!$ this ->negated ? $ removedType : $ intersectedType ) : $ traverse ($ type ),
126+ );
129127
130128 if ($ isSuperType ->yes ()) {
131129 return $ yesType ();
0 commit comments