@@ -182,7 +182,7 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
182
182
} else {
183
183
$ canAccessProperty = $ scope ->getClassReflection ()->getName ();
184
184
}
185
- $ description = $ this ->describe (VerbosityLevel:: cache () );
185
+ $ description = $ this ->describeCache ( );
186
186
187
187
if (isset (self ::$ properties [$ description ][$ propertyName ][$ canAccessProperty ])) {
188
188
return self ::$ properties [$ description ][$ propertyName ][$ canAccessProperty ];
@@ -321,8 +321,14 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
321
321
return IsSuperTypeOfResult::createNo ();
322
322
}
323
323
324
- $ thisDescription = $ this ->describe (VerbosityLevel::cache ());
325
- $ description = $ type ->describe (VerbosityLevel::cache ());
324
+ $ thisDescription = $ this ->describeCache ();
325
+
326
+ if ($ type instanceof self) {
327
+ $ description = $ type ->describeCache ();
328
+ } else {
329
+ $ description = $ type ->describe (VerbosityLevel::cache ());
330
+ }
331
+
326
332
if (isset (self ::$ superTypes [$ thisDescription ][$ description ])) {
327
333
return self ::$ superTypes [$ thisDescription ][$ description ];
328
334
}
@@ -510,33 +516,15 @@ public function describe(VerbosityLevel $level): string
510
516
$ preciseNameCallback ,
511
517
$ preciseWithSubtracted ,
512
518
function () use ($ preciseWithSubtracted ): string {
513
- if ($ this ->cachedDescription !== null ) {
514
- return $ this ->cachedDescription ;
515
- }
516
-
517
- $ description = $ preciseWithSubtracted ();
518
-
519
- if ($ this instanceof GenericObjectType) {
520
- $ description .= '< ' ;
521
- $ typeDescriptions = [];
522
- foreach ($ this ->getTypes () as $ type ) {
523
- $ typeDescriptions [] = $ type ->describe (VerbosityLevel::cache ());
524
- }
525
- $ description .= '< ' . implode (', ' , $ typeDescriptions ) . '> ' ;
526
- }
527
-
528
519
$ reflection = $ this ->classReflection ;
520
+ $ line = '' ;
529
521
if ($ reflection !== null ) {
530
- $ description .= '- ' ;
531
- $ description .= (string ) $ reflection ->getNativeReflection ()->getStartLine ();
532
- $ description .= '- ' ;
533
-
534
- if ($ reflection ->hasFinalByKeywordOverride ()) {
535
- $ description .= 'f= ' . ($ reflection ->isFinalByKeyword () ? 't ' : 'f ' );
536
- }
522
+ $ line .= '- ' ;
523
+ $ line .= (string ) $ reflection ->getNativeReflection ()->getStartLine ();
524
+ $ line .= '- ' ;
537
525
}
538
526
539
- return $ this -> cachedDescription = $ description . $ this ->describeAdditionalCacheKey ();
527
+ return $ preciseWithSubtracted () . ' - ' . static ::class . ' - ' . $ line . $ this ->describeAdditionalCacheKey ();
540
528
},
541
529
);
542
530
}
@@ -546,6 +534,47 @@ protected function describeAdditionalCacheKey(): string
546
534
return '' ;
547
535
}
548
536
537
+ private function describeCache (): string
538
+ {
539
+ if ($ this ->cachedDescription !== null ) {
540
+ return $ this ->cachedDescription ;
541
+ }
542
+
543
+ if (static ::class !== self ::class) {
544
+ return $ this ->cachedDescription = $ this ->describe (VerbosityLevel::cache ());
545
+ }
546
+
547
+ $ description = $ this ->className ;
548
+
549
+ if ($ this instanceof GenericObjectType) {
550
+ $ description .= '< ' ;
551
+ $ typeDescriptions = [];
552
+ foreach ($ this ->getTypes () as $ type ) {
553
+ $ typeDescriptions [] = $ type ->describe (VerbosityLevel::cache ());
554
+ }
555
+ $ description .= '< ' . implode (', ' , $ typeDescriptions ) . '> ' ;
556
+ }
557
+
558
+ if ($ this ->subtractedType !== null ) {
559
+ $ description .= $ this ->subtractedType instanceof UnionType
560
+ ? sprintf ('~(%s) ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()))
561
+ : sprintf ('~%s ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()));
562
+ }
563
+
564
+ $ reflection = $ this ->classReflection ;
565
+ if ($ reflection !== null ) {
566
+ $ description .= '- ' ;
567
+ $ description .= (string ) $ reflection ->getNativeReflection ()->getStartLine ();
568
+ $ description .= '- ' ;
569
+
570
+ if ($ reflection ->hasFinalByKeywordOverride ()) {
571
+ $ description .= 'f= ' . ($ reflection ->isFinalByKeyword () ? 't ' : 'f ' );
572
+ }
573
+ }
574
+
575
+ return $ this ->cachedDescription = $ description ;
576
+ }
577
+
549
578
public function toNumber (): Type
550
579
{
551
580
if ($ this ->isInstanceOf ('SimpleXMLElement ' )->yes ()) {
@@ -748,7 +777,7 @@ public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAcce
748
777
} else {
749
778
$ canCallMethod = $ scope ->getClassReflection ()->getName ();
750
779
}
751
- $ description = $ this ->describe (VerbosityLevel:: cache () );
780
+ $ description = $ this ->describeCache ( );
752
781
if (isset (self ::$ methods [$ description ][$ methodName ][$ canCallMethod ])) {
753
782
return self ::$ methods [$ description ][$ methodName ][$ canCallMethod ];
754
783
}
@@ -1237,7 +1266,7 @@ public function getEnumCases(): array
1237
1266
return [];
1238
1267
}
1239
1268
1240
- $ cacheKey = $ this ->describe (VerbosityLevel:: cache () );
1269
+ $ cacheKey = $ this ->describeCache ( );
1241
1270
if (array_key_exists ($ cacheKey , self ::$ enumCases )) {
1242
1271
return self ::$ enumCases [$ cacheKey ];
1243
1272
}
@@ -1500,7 +1529,7 @@ public function getAncestorWithClassName(string $className): ?self
1500
1529
return $ this ->currentAncestors [$ className ];
1501
1530
}
1502
1531
1503
- $ description = $ this ->describe (VerbosityLevel:: cache () );
1532
+ $ description = $ this ->describeCache ( );
1504
1533
if (
1505
1534
array_key_exists ($ description , self ::$ ancestors )
1506
1535
&& array_key_exists ($ className , self ::$ ancestors [$ description ])
0 commit comments