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: [],
85: TrinaryLogic::createYes(),
86: );
87: }
88:
89: public function toArrayKey(): Type
90: {
91: return new ErrorType();
92: }
93:
94: public function isOffsetAccessLegal(): TrinaryLogic
95: {
96: return TrinaryLogic::createYes();
97: }
98:
99: public function isScalar(): TrinaryLogic
100: {
101: return TrinaryLogic::createNo();
102: }
103:
104: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
105: {
106: return new BooleanType();
107: }
108:
109: public function exponentiate(Type $exponent): Type
110: {
111: return new ErrorType();
112: }
113:
114: public function getFiniteTypes(): array
115: {
116: return [];
117: }
118:
119: public function toPhpDocNode(): TypeNode
120: {
121: return new IdentifierTypeNode('resource');
122: }
123:
124: }
125: