@@ -686,42 +686,32 @@ public function isIterableAtLeastOnce(): TrinaryLogic
686
686
public function getIterableKeyType (): Type
687
687
{
688
688
$ isTraversable = false ;
689
+ if ($ this ->isInstanceOf (IteratorAggregate::class)->yes ()) {
690
+ $ keyType = RecursionGuard::run ($ this , fn (): Type => ParametersAcceptorSelector::selectSingle (
691
+ $ this ->getMethod ('getIterator ' , new OutOfClassScope ())->getVariants (),
692
+ )->getReturnType ()->getIterableKeyType ());
693
+ $ isTraversable = true ;
694
+ if (!$ keyType instanceof MixedType || $ keyType ->isExplicitMixed ()) {
695
+ return $ keyType ;
696
+ }
697
+ }
698
+
689
699
if ($ this ->isInstanceOf (Traversable::class)->yes ()) {
690
700
$ isTraversable = true ;
691
701
$ tKey = GenericTypeVariableResolver::getType ($ this , Traversable::class, 'TKey ' );
692
702
if ($ tKey !== null ) {
693
703
if (!$ tKey instanceof MixedType || $ tKey ->isExplicitMixed ()) {
694
- $ classReflection = $ this ->getClassReflection ();
695
- if ($ classReflection === null ) {
696
- return $ tKey ;
697
- }
698
-
699
- return TypeTraverser::map ($ tKey , static function (Type $ type , callable $ traverse ) use ($ classReflection ): Type {
700
- if ($ type instanceof StaticType) {
701
- return $ type ->changeBaseClass ($ classReflection )->getStaticObjectType ();
702
- }
703
-
704
- return $ traverse ($ type );
705
- });
704
+ return $ tKey ;
706
705
}
707
706
}
708
707
}
708
+
709
709
if ($ this ->isInstanceOf (Iterator::class)->yes ()) {
710
710
return RecursionGuard::run ($ this , fn (): Type => ParametersAcceptorSelector::selectSingle (
711
711
$ this ->getMethod ('key ' , new OutOfClassScope ())->getVariants (),
712
712
)->getReturnType ());
713
713
}
714
714
715
- if ($ this ->isInstanceOf (IteratorAggregate::class)->yes ()) {
716
- $ keyType = RecursionGuard::run ($ this , fn (): Type => ParametersAcceptorSelector::selectSingle (
717
- $ this ->getMethod ('getIterator ' , new OutOfClassScope ())->getVariants (),
718
- )->getReturnType ()->getIterableKeyType ());
719
- $ isTraversable = true ;
720
- if (!$ keyType instanceof MixedType || $ keyType ->isExplicitMixed ()) {
721
- return $ keyType ;
722
- }
723
- }
724
-
725
715
if ($ isTraversable ) {
726
716
return new MixedType ();
727
717
}
@@ -732,23 +722,22 @@ public function getIterableKeyType(): Type
732
722
public function getIterableValueType (): Type
733
723
{
734
724
$ isTraversable = false ;
725
+ if ($ this ->isInstanceOf (IteratorAggregate::class)->yes ()) {
726
+ $ valueType = RecursionGuard::run ($ this , fn (): Type => ParametersAcceptorSelector::selectSingle (
727
+ $ this ->getMethod ('getIterator ' , new OutOfClassScope ())->getVariants (),
728
+ )->getReturnType ()->getIterableValueType ());
729
+ $ isTraversable = true ;
730
+ if (!$ valueType instanceof MixedType || $ valueType ->isExplicitMixed ()) {
731
+ return $ valueType ;
732
+ }
733
+ }
734
+
735
735
if ($ this ->isInstanceOf (Traversable::class)->yes ()) {
736
736
$ isTraversable = true ;
737
737
$ tValue = GenericTypeVariableResolver::getType ($ this , Traversable::class, 'TValue ' );
738
738
if ($ tValue !== null ) {
739
739
if (!$ tValue instanceof MixedType || $ tValue ->isExplicitMixed ()) {
740
- $ classReflection = $ this ->getClassReflection ();
741
- if ($ classReflection === null ) {
742
- return $ tValue ;
743
- }
744
-
745
- return TypeTraverser::map ($ tValue , static function (Type $ type , callable $ traverse ) use ($ classReflection ): Type {
746
- if ($ type instanceof StaticType) {
747
- return $ type ->changeBaseClass ($ classReflection )->getStaticObjectType ();
748
- }
749
-
750
- return $ traverse ($ type );
751
- });
740
+ return $ tValue ;
752
741
}
753
742
}
754
743
}
@@ -759,16 +748,6 @@ public function getIterableValueType(): Type
759
748
)->getReturnType ());
760
749
}
761
750
762
- if ($ this ->isInstanceOf (IteratorAggregate::class)->yes ()) {
763
- $ valueType = RecursionGuard::run ($ this , fn (): Type => ParametersAcceptorSelector::selectSingle (
764
- $ this ->getMethod ('getIterator ' , new OutOfClassScope ())->getVariants (),
765
- )->getReturnType ()->getIterableValueType ());
766
- $ isTraversable = true ;
767
- if (!$ valueType instanceof MixedType || $ valueType ->isExplicitMixed ()) {
768
- return $ valueType ;
769
- }
770
- }
771
-
772
751
if ($ isTraversable ) {
773
752
return new MixedType ();
774
753
}
0 commit comments