| 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: | interface TypeWithClassName extends Type |
| 25: | { |
| 26: | |
| 27: | public function getClassName(): string; |
| 28: | |
| 29: | /** |
| 30: | * Returns this type projected onto an ancestor class, preserving generic type arguments. |
| 31: | */ |
| 32: | public function getAncestorWithClassName(string $className): ?self; |
| 33: | |
| 34: | public function getClassReflection(): ?ClassReflection; |
| 35: | |
| 36: | } |
| 37: |