1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\Php\PhpVersion;
6: use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
7: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
8: use PHPStan\TrinaryLogic;
9: use PHPStan\Turbo\ShadowedByTurboExtension;
10: use PHPStan\Type\Constant\ConstantArrayType;
11: use PHPStan\Type\Constant\ConstantIntegerType;
12: use PHPStan\Type\Traits\NonArrayTypeTrait;
13: use PHPStan\Type\Traits\NonCallableTypeTrait;
14: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
15: use PHPStan\Type\Traits\NonGenericTypeTrait;
16: use PHPStan\Type\Traits\NonIterableTypeTrait;
17: use PHPStan\Type\Traits\NonObjectTypeTrait;
18: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
19: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
20: use PHPStan\Type\Traits\OperatorTypeTrait;
21: use PHPStan\Type\Traits\TruthyBooleanTypeTrait;
22: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
23:
24: /** @api */
25: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/ResourceType.cpp')]
26: class ResourceType implements Type
27: {
28:
29: use JustNullableTypeTrait;
30: use NonArrayTypeTrait;
31: use NonCallableTypeTrait;
32: use NonIterableTypeTrait;
33: use NonObjectTypeTrait;
34: use TruthyBooleanTypeTrait;
35: use NonGenericTypeTrait;
36: use UndecidedComparisonTypeTrait;
37: use NonOffsetAccessibleTypeTrait;
38: use NonRemoveableTypeTrait;
39: use NonGeneralizableTypeTrait;
40: use OperatorTypeTrait;
41:
42: /** @api */
43: public function __construct()
44: {
45: }
46:
47: public function describe(VerbosityLevel $level): string
48: {
49: return 'resource';
50: }
51:
52: public function getConstantStrings(): array
53: {
54: return [];
55: }
56:
57: public function toNumber(): Type
58: {
59: return new ErrorType();
60: }
61:
62: public function toBitwiseNotType(): Type
63: {
64: return new ErrorType();
65: }
66:
67: public function toAbsoluteNumber(): Type
68: {
69: return new ErrorType();
70: }
71:
72: public function toString(): Type
73: {
74: return new StringType();
75: }
76:
77: public function toInteger(): Type
78: {
79: return new IntegerType();
80: }
81:
82: public function toFloat(): Type
83: {
84: return new FloatType();
85: }
86:
87: public function toArray(): Type
88: {
89: return new ConstantArrayType(
90: [new ConstantIntegerType(0)],
91: [$this],
92: [1],
93: isList: TrinaryLogic::createYes(),
94: );
95: }
96:
97: public function toArrayKey(): Type
98: {
99: return new ErrorType();
100: }
101:
102: public function toCoercedArgumentType(bool $strictTypes): Type
103: {
104: return $this;
105: }
106:
107: public function isOffsetAccessLegal(): TrinaryLogic
108: {
109: return TrinaryLogic::createYes();
110: }
111:
112: public function isScalar(): TrinaryLogic
113: {
114: return TrinaryLogic::createNo();
115: }
116:
117: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
118: {
119: return new BooleanType();
120: }
121:
122: public function arithmeticPower(Type $exponent, PhpVersion $phpVersion): Type
123: {
124: return new ErrorType();
125: }
126:
127: public function getFiniteTypes(): array
128: {
129: return [];
130: }
131:
132: public function toPhpDocNode(): TypeNode
133: {
134: return new IdentifierTypeNode('resource');
135: }
136:
137: public function toNativePhpTypeNode(NativeTypePosition $position)
138: {
139: return null;
140: }
141:
142: public function hasTemplateOrLateResolvableType(): bool
143: {
144: return false;
145: }
146:
147: public function toValueSet(): ValueSet
148: {
149: return ValueSet::createResources();
150: }
151:
152: }
153: