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 toString(): Type
59: {
60: return new StringType();
61: }
62:
63: public function toInteger(): Type
64: {
65: return new IntegerType();
66: }
67:
68: public function toFloat(): Type
69: {
70: return new ErrorType();
71: }
72:
73: public function toArray(): Type
74: {
75: return new ConstantArrayType(
76: [new ConstantIntegerType(0)],
77: [$this],
78: [1],
79: [],
80: TrinaryLogic::createYes(),
81: );
82: }
83:
84: public function toArrayKey(): Type
85: {
86: return new ErrorType();
87: }
88:
89: public function isOffsetAccessLegal(): TrinaryLogic
90: {
91: return TrinaryLogic::createYes();
92: }
93:
94: public function isScalar(): TrinaryLogic
95: {
96: return TrinaryLogic::createNo();
97: }
98:
99: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
100: {
101: return new BooleanType();
102: }
103:
104: public function exponentiate(Type $exponent): Type
105: {
106: return new ErrorType();
107: }
108:
109: public function getFiniteTypes(): array
110: {
111: return [];
112: }
113:
114: public function toPhpDocNode(): TypeNode
115: {
116: return new IdentifierTypeNode('resource');
117: }
118:
119: /**
120: * @param mixed[] $properties
121: */
122: public static function __set_state(array $properties): Type
123: {
124: return new self();
125: }
126:
127: }
128: