4646use PHPStan \Type \Traits \NonArrayTypeTrait ;
4747use PHPStan \Type \Traits \NonGeneralizableTypeTrait ;
4848use PHPStan \Type \Traits \NonGenericTypeTrait ;
49+ use PHPStan \Type \Traits \SubstractableTypeTrait ;
4950use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
5051use Stringable ;
5152use Throwable ;
@@ -68,6 +69,7 @@ class ObjectType implements TypeWithClassName, SubtractableType
6869 use NonGenericTypeTrait;
6970 use UndecidedComparisonTypeTrait;
7071 use NonGeneralizableTypeTrait;
72+ use SubstractableTypeTrait;
7173
7274 private const EXTRA_OFFSET_CLASSES = [
7375 'DOMNamedNodeMap ' , // Only read and existence
@@ -504,16 +506,7 @@ public function describe(VerbosityLevel $level): string
504506 return $ reflectionProvider ->getClassName ($ this ->className );
505507 };
506508
507- $ preciseWithSubtracted = function () use ($ level ): string {
508- $ description = $ this ->className ;
509- if ($ this ->subtractedType !== null ) {
510- $ description .= $ this ->subtractedType instanceof UnionType
511- ? sprintf ('~(%s) ' , $ this ->subtractedType ->describe ($ level ))
512- : sprintf ('~%s ' , $ this ->subtractedType ->describe ($ level ));
513- }
514-
515- return $ description ;
516- };
509+ $ preciseWithSubtracted = fn (): string => $ this ->className . $ this ->describeSubtractedType ($ this ->subtractedType , $ level );
517510
518511 return $ level ->handle (
519512 $ preciseNameCallback ,
@@ -559,11 +552,7 @@ private function describeCache(): string
559552 $ description .= '< ' . implode (', ' , $ typeDescriptions ) . '> ' ;
560553 }
561554
562- if ($ this ->subtractedType !== null ) {
563- $ description .= $ this ->subtractedType instanceof UnionType
564- ? sprintf ('~(%s) ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()))
565- : sprintf ('~%s ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()));
566- }
555+ $ description .= $ this ->describeSubtractedType ($ this ->subtractedType , VerbosityLevel::cache ());
567556
568557 $ reflection = $ this ->classReflection ;
569558 if ($ reflection !== null ) {
0 commit comments