1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\Reflection\ClassReflection;
6:
7: /**
8: * A Type that represents an object with a known class name.
9: *
10: * Implemented by ObjectType, StaticType, ThisType, EnumCaseObjectType, ClosureType,
11: * and GenericObjectType. Provides access to the class name and its ClassReflection.
12: *
13: * This interface is used when code needs to work with any object type that has a
14: * specific class — for example, Scope::resolveTypeByName() returns TypeWithClassName
15: * because the resolved type always has a known class.
16: *
17: * Note: Do not use `instanceof TypeWithClassName` to check if a type is an object.
18: * Use `$type->getObjectClassNames()` or `$type->isObject()` instead, which correctly
19: * handles union types and intersection types.
20: *
21: * @api
22: * @api-do-not-implement
23: */
24: #[InstanceofDeprecated(insteadUse: 'Type::getObjectClassNames() or Type::getObjectClassReflections()')]
25: interface TypeWithClassName extends Type
26: {
27:
28: public function getClassName(): string;
29:
30: /**
31: * Returns this type projected onto an ancestor class, preserving generic type arguments.
32: */
33: public function getAncestorWithClassName(string $className): ?self;
34:
35: public function getClassReflection(): ?ClassReflection;
36:
37: }
38: