1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
6: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
7: use PHPStan\TrinaryLogic;
8: use PHPStan\Turbo\ShadowedByTurboExtension;
9:
10: /** @api */
11: #[InstanceofDeprecated(insteadUse: 'Type::isClassStringType()')]
12: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/ClassStringType.cpp')]
13: class ClassStringType extends StringType
14: {
15:
16: /** @api */
17: public function __construct()
18: {
19: parent::__construct();
20: }
21:
22: public function describe(VerbosityLevel $level): string
23: {
24: return 'class-string';
25: }
26:
27: public function accepts(Type $type, bool $strictTypes): AcceptsResult
28: {
29: if ($type instanceof CompoundType) {
30: return $type->isAcceptedBy($this, $strictTypes);
31: }
32:
33: return new AcceptsResult($type->isClassString(), []);
34: }
35:
36: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
37: {
38: if ($type instanceof CompoundType) {
39: return $type->isSubTypeOf($this);
40: }
41:
42: return IsSuperTypeOfResult::createFromTrinaryLogic($type->isClassString());
43: }
44:
45: public function isString(): TrinaryLogic
46: {
47: return TrinaryLogic::createYes();
48: }
49:
50: public function isNumericString(): TrinaryLogic
51: {
52: return TrinaryLogic::createNo();
53: }
54:
55: public function isDecimalIntegerString(): TrinaryLogic
56: {
57: return TrinaryLogic::createNo();
58: }
59:
60: public function isNonEmptyString(): TrinaryLogic
61: {
62: return TrinaryLogic::createYes();
63: }
64:
65: public function isNonFalsyString(): TrinaryLogic
66: {
67: return TrinaryLogic::createYes();
68: }
69:
70: public function isLiteralString(): TrinaryLogic
71: {
72: return TrinaryLogic::createMaybe();
73: }
74:
75: /** Class names are not a refinement of the string accessories. */
76: public function getStringRefinement(): ?int
77: {
78: return null;
79: }
80:
81: public function isLowercaseString(): TrinaryLogic
82: {
83: return TrinaryLogic::createMaybe();
84: }
85:
86: public function isUppercaseString(): TrinaryLogic
87: {
88: return TrinaryLogic::createMaybe();
89: }
90:
91: public function isClassString(): TrinaryLogic
92: {
93: return TrinaryLogic::createYes();
94: }
95:
96: public function getClassStringObjectType(): Type
97: {
98: return new ObjectWithoutClassType();
99: }
100:
101: public function getObjectTypeOrClassStringObjectType(): Type
102: {
103: return new ObjectWithoutClassType();
104: }
105:
106: public function toPhpDocNode(): TypeNode
107: {
108: return new IdentifierTypeNode('class-string');
109: }
110:
111: }
112: