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\Traits\FalseyBooleanTypeTrait;
10: use PHPStan\Type\Traits\NonArrayTypeTrait;
11: use PHPStan\Type\Traits\NonCallableTypeTrait;
12: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
13: use PHPStan\Type\Traits\NonGenericTypeTrait;
14: use PHPStan\Type\Traits\NonIterableTypeTrait;
15: use PHPStan\Type\Traits\NonObjectTypeTrait;
16: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
17: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
18: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
19:
20: /** @api */
21: class VoidType implements Type
22: {
23:
24: use NonArrayTypeTrait;
25: use NonCallableTypeTrait;
26: use NonIterableTypeTrait;
27: use NonObjectTypeTrait;
28: use NonOffsetAccessibleTypeTrait;
29: use FalseyBooleanTypeTrait;
30: use NonGenericTypeTrait;
31: use UndecidedComparisonTypeTrait;
32: use NonRemoveableTypeTrait;
33: use NonGeneralizableTypeTrait;
34:
35: /** @api */
36: public function __construct()
37: {
38: }
39:
40: /**
41: * @return string[]
42: */
43: public function getReferencedClasses(): array
44: {
45: return [];
46: }
47:
48: public function getObjectClassNames(): array
49: {
50: return [];
51: }
52:
53: public function getObjectClassReflections(): array
54: {
55: return [];
56: }
57:
58: public function accepts(Type $type, bool $strictTypes): TrinaryLogic
59: {
60: return $this->acceptsWithReason($type, $strictTypes)->result;
61: }
62:
63: public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
64: {
65: if ($type instanceof CompoundType) {
66: return $type->isAcceptedWithReasonBy($this, $strictTypes);
67: }
68:
69: return new AcceptsResult($type->isVoid()->or($type->isNull()), []);
70: }
71:
72: public function isSuperTypeOf(Type $type): TrinaryLogic
73: {
74: if ($type instanceof self) {
75: return TrinaryLogic::createYes();
76: }
77:
78: if ($type instanceof CompoundType) {
79: return $type->isSubTypeOf($this);
80: }
81:
82: return TrinaryLogic::createNo();
83: }
84:
85: public function equals(Type $type): bool
86: {
87: return $type instanceof self;
88: }
89:
90: public function describe(VerbosityLevel $level): string
91: {
92: return 'void';
93: }
94:
95: public function toNumber(): Type
96: {
97: return new ErrorType();
98: }
99:
100: public function toString(): Type
101: {
102: return new ErrorType();
103: }
104:
105: public function toInteger(): Type
106: {
107: return new ErrorType();
108: }
109:
110: public function toFloat(): Type
111: {
112: return new ErrorType();
113: }
114:
115: public function toArray(): Type
116: {
117: return new ErrorType();
118: }
119:
120: public function toArrayKey(): Type
121: {
122: return new ErrorType();
123: }
124:
125: public function isOffsetAccessLegal(): TrinaryLogic
126: {
127: return TrinaryLogic::createYes();
128: }
129:
130: public function isNull(): TrinaryLogic
131: {
132: return TrinaryLogic::createNo();
133: }
134:
135: public function isConstantValue(): TrinaryLogic
136: {
137: return TrinaryLogic::createNo();
138: }
139:
140: public function isConstantScalarValue(): TrinaryLogic
141: {
142: return TrinaryLogic::createNo();
143: }
144:
145: public function getConstantScalarTypes(): array
146: {
147: return [];
148: }
149:
150: public function getConstantScalarValues(): array
151: {
152: return [];
153: }
154:
155: public function isTrue(): TrinaryLogic
156: {
157: return TrinaryLogic::createNo();
158: }
159:
160: public function isFalse(): TrinaryLogic
161: {
162: return TrinaryLogic::createNo();
163: }
164:
165: public function isBoolean(): TrinaryLogic
166: {
167: return TrinaryLogic::createNo();
168: }
169:
170: public function isFloat(): TrinaryLogic
171: {
172: return TrinaryLogic::createNo();
173: }
174:
175: public function isInteger(): TrinaryLogic
176: {
177: return TrinaryLogic::createNo();
178: }
179:
180: public function isString(): TrinaryLogic
181: {
182: return TrinaryLogic::createNo();
183: }
184:
185: public function isNumericString(): TrinaryLogic
186: {
187: return TrinaryLogic::createNo();
188: }
189:
190: public function isNonEmptyString(): TrinaryLogic
191: {
192: return TrinaryLogic::createNo();
193: }
194:
195: public function isNonFalsyString(): TrinaryLogic
196: {
197: return TrinaryLogic::createNo();
198: }
199:
200: public function isLiteralString(): TrinaryLogic
201: {
202: return TrinaryLogic::createNo();
203: }
204:
205: public function isClassStringType(): TrinaryLogic
206: {
207: return TrinaryLogic::createNo();
208: }
209:
210: public function getClassStringObjectType(): Type
211: {
212: return new ErrorType();
213: }
214:
215: public function getObjectTypeOrClassStringObjectType(): Type
216: {
217: return new ErrorType();
218: }
219:
220: public function isVoid(): TrinaryLogic
221: {
222: return TrinaryLogic::createYes();
223: }
224:
225: public function isScalar(): TrinaryLogic
226: {
227: return TrinaryLogic::createNo();
228: }
229:
230: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
231: {
232: return new BooleanType();
233: }
234:
235: public function traverse(callable $cb): Type
236: {
237: return $this;
238: }
239:
240: public function traverseSimultaneously(Type $right, callable $cb): Type
241: {
242: return $this;
243: }
244:
245: public function exponentiate(Type $exponent): Type
246: {
247: return new ErrorType();
248: }
249:
250: public function getFiniteTypes(): array
251: {
252: return [];
253: }
254:
255: public function toPhpDocNode(): TypeNode
256: {
257: return new IdentifierTypeNode('void');
258: }
259:
260: /**
261: * @param mixed[] $properties
262: */
263: public static function __set_state(array $properties): Type
264: {
265: return new self();
266: }
267:
268: }
269: