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