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\Type\Constant\ConstantArrayType;
10: use PHPStan\Type\Constant\ConstantIntegerType;
11: use PHPStan\Type\Traits\NonArrayTypeTrait;
12: use PHPStan\Type\Traits\NonCallableTypeTrait;
13: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
14: use PHPStan\Type\Traits\NonGenericTypeTrait;
15: use PHPStan\Type\Traits\NonIterableTypeTrait;
16: use PHPStan\Type\Traits\NonObjectTypeTrait;
17: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
18: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
19: use PHPStan\Type\Traits\TruthyBooleanTypeTrait;
20: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
21:
22: /** @api */
23: class ResourceType implements Type
24: {
25:
26: use JustNullableTypeTrait;
27: use NonArrayTypeTrait;
28: use NonCallableTypeTrait;
29: use NonIterableTypeTrait;
30: use NonObjectTypeTrait;
31: use TruthyBooleanTypeTrait;
32: use NonGenericTypeTrait;
33: use UndecidedComparisonTypeTrait;
34: use NonOffsetAccessibleTypeTrait;
35: use NonRemoveableTypeTrait;
36: use NonGeneralizableTypeTrait;
37:
38: /** @api */
39: public function __construct()
40: {
41: }
42:
43: public function describe(VerbosityLevel $level): string
44: {
45: return 'resource';
46: }
47:
48: public function getConstantStrings(): array
49: {
50: return [];
51: }
52:
53: public function toNumber(): Type
54: {
55: return new ErrorType();
56: }
57:
58: public function toAbsoluteNumber(): Type
59: {
60: return new ErrorType();
61: }
62:
63: public function toString(): Type
64: {
65: return new StringType();
66: }
67:
68: public function toInteger(): Type
69: {
70: return new IntegerType();
71: }
72:
73: public function toFloat(): Type
74: {
75: return new ErrorType();
76: }
77:
78: public function toArray(): Type
79: {
80: return new ConstantArrayType(
81: [new ConstantIntegerType(0)],
82: [$this],
83: [1],
84: isList: TrinaryLogic::createYes(),
85: );
86: }
87:
88: public function toArrayKey(): Type
89: {
90: return new ErrorType();
91: }
92:
93: public function toCoercedArgumentType(bool $strictTypes): Type
94: {
95: return $this;
96: }
97:
98: public function isOffsetAccessLegal(): TrinaryLogic
99: {
100: return TrinaryLogic::createYes();
101: }
102:
103: public function isScalar(): TrinaryLogic
104: {
105: return TrinaryLogic::createNo();
106: }
107:
108: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
109: {
110: return new BooleanType();
111: }
112:
113: public function exponentiate(Type $exponent): Type
114: {
115: return new ErrorType();
116: }
117:
118: public function getFiniteTypes(): array
119: {
120: return [];
121: }
122:
123: public function toPhpDocNode(): TypeNode
124: {
125: return new IdentifierTypeNode('resource');
126: }
127:
128: }
129: