4747use PHPStan \Type \Traits \NonArrayTypeTrait ;
4848use PHPStan \Type \Traits \NonGeneralizableTypeTrait ;
4949use PHPStan \Type \Traits \NonGenericTypeTrait ;
50+ use PHPStan \Type \Traits \SubstractableTypeTrait ;
5051use PHPStan \Type \Traits \UndecidedComparisonTypeTrait ;
5152use Stringable ;
5253use Throwable ;
@@ -69,6 +70,7 @@ class ObjectType implements TypeWithClassName, SubtractableType
6970 use NonGenericTypeTrait;
7071 use UndecidedComparisonTypeTrait;
7172 use NonGeneralizableTypeTrait;
73+ use SubstractableTypeTrait;
7274
7375 private const EXTRA_OFFSET_CLASSES = [
7476 'DOMNamedNodeMap ' , // Only read and existence
@@ -505,16 +507,7 @@ public function describe(VerbosityLevel $level): string
505507 return $ reflectionProvider ->getClassName ($ this ->className );
506508 };
507509
508- $ preciseWithSubtracted = function () use ($ level ): string {
509- $ description = $ this ->className ;
510- if ($ this ->subtractedType !== null ) {
511- $ description .= $ this ->subtractedType instanceof UnionType
512- ? sprintf ('~(%s) ' , $ this ->subtractedType ->describe ($ level ))
513- : sprintf ('~%s ' , $ this ->subtractedType ->describe ($ level ));
514- }
515- 516- return $ description ;
517- };
510+ $ preciseWithSubtracted = fn (): string => $ this ->className . $ this ->describeSubtractedType ($ this ->subtractedType , $ level );
518511
519512 return $ level ->handle (
520513 $ preciseNameCallback ,
@@ -560,11 +553,7 @@ private function describeCache(): string
560553 $ description .= '< ' . implode (', ' , $ typeDescriptions ) . '> ' ;
561554 }
562555
563- if ($ this ->subtractedType !== null ) {
564- $ description .= $ this ->subtractedType instanceof UnionType
565- ? sprintf ('~(%s) ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()))
566- : sprintf ('~%s ' , $ this ->subtractedType ->describe (VerbosityLevel::cache ()));
567- }
556+ $ description .= $ this ->describeSubtractedType ($ this ->subtractedType , VerbosityLevel::cache ());
568557
569558 $ reflection = $ this ->classReflection ;
570559 if ($ reflection !== null ) {
0 commit comments