@@ -200,6 +200,7 @@ public function __construct(
200
200
private bool $ treatPhpDocTypesAsCertain = true ,
201
201
private bool $ afterExtractCall = false ,
202
202
private ?Scope $ parentScope = null ,
203
+ private bool $ explicitMixedInUnknownGenericNew = false ,
203
204
)
204
205
{
205
206
if ($ namespace === '' ) {
@@ -2894,6 +2895,7 @@ public function doNotTreatPhpDocTypesAsCertain(): Scope
2894
2895
false ,
2895
2896
$ this ->afterExtractCall ,
2896
2897
$ this ->parentScope ,
2898
+ $ this ->explicitMixedInUnknownGenericNew ,
2897
2899
);
2898
2900
}
2899
2901
@@ -5649,9 +5651,36 @@ private function exactInstantiation(New_ $node, string $className): ?Type
5649
5651
$ constructorMethod ->getVariants (),
5650
5652
);
5651
5653
5654
+ if ($ this ->explicitMixedInUnknownGenericNew ) {
5655
+ return new GenericObjectType (
5656
+ $ resolvedClassName ,
5657
+ $ classReflection ->typeMapToList ($ parametersAcceptor ->getResolvedTemplateTypeMap ()),
5658
+ );
5659
+ }
5660
+
5661
+ $ resolvedPhpDoc = $ classReflection ->getResolvedPhpDoc ();
5662
+ if ($ resolvedPhpDoc === null ) {
5663
+ return $ objectType ;
5664
+ }
5665
+
5666
+ $ list = [];
5667
+ $ typeMap = $ parametersAcceptor ->getResolvedTemplateTypeMap ();
5668
+ foreach ($ resolvedPhpDoc ->getTemplateTags () as $ tag ) {
5669
+ $ templateType = $ typeMap ->getType ($ tag ->getName ());
5670
+ if ($ templateType !== null ) {
5671
+ $ list [] = $ templateType ;
5672
+ continue ;
5673
+ }
5674
+ $ bound = $ tag ->getBound ();
5675
+ if ($ bound instanceof MixedType && $ bound ->isExplicitMixed ()) {
5676
+ $ bound = new MixedType (false );
5677
+ }
5678
+ $ list [] = $ bound ;
5679
+ }
5680
+
5652
5681
return new GenericObjectType (
5653
5682
$ resolvedClassName ,
5654
- $ classReflection -> typeMapToList ( $ parametersAcceptor -> getResolvedTemplateTypeMap ()) ,
5683
+ $ list ,
5655
5684
);
5656
5685
}
5657
5686
0 commit comments