1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PhpParser\Node\Identifier;
6: use PHPStan\Php\PhpVersion;
7: use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
8: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
9: use PHPStan\TrinaryLogic;
10: use PHPStan\Turbo\ShadowedByTurboExtension;
11: use PHPStan\Type\Traits\FalseyBooleanTypeTrait;
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\UndecidedComparisonTypeTrait;
22:
23: /** @api */
24: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/VoidType.cpp')]
25: #[InstanceofDeprecated(insteadUse: 'Type::isVoid()')]
26: class VoidType implements Type
27: {
28:
29: use NonArrayTypeTrait;
30: use NonCallableTypeTrait;
31: use NonIterableTypeTrait;
32: use NonObjectTypeTrait;
33: use NonOffsetAccessibleTypeTrait;
34: use FalseyBooleanTypeTrait;
35: use NonGenericTypeTrait;
36: use UndecidedComparisonTypeTrait;
37: use NonRemoveableTypeTrait;
38: use NonGeneralizableTypeTrait;
39: use OperatorTypeTrait;
40:
41: /** @api */
42: public function __construct()
43: {
44: }
45:
46: public function getReferencedClasses(): array
47: {
48: return [];
49: }
50:
51: public function getObjectClassNames(): array
52: {
53: return [];
54: }
55:
56: public function getObjectClassReflections(): array
57: {
58: return [];
59: }
60:
61: public function accepts(Type $type, bool $strictTypes): AcceptsResult
62: {
63: if ($type instanceof CompoundType) {
64: return $type->isAcceptedBy($this, $strictTypes);
65: }
66:
67: return new AcceptsResult($type->isVoid()->or($type->isNull()), []);
68: }
69:
70: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
71: {
72: if ($type instanceof self) {
73: return IsSuperTypeOfResult::createYes();
74: }
75:
76: if ($type instanceof CompoundType) {
77: return $type->isSubTypeOf($this);
78: }
79:
80: return IsSuperTypeOfResult::createNo();
81: }
82:
83: public function equals(Type $type): bool
84: {
85: return $type instanceof self;
86: }
87:
88: public function describe(VerbosityLevel $level): string
89: {
90: return 'void';
91: }
92:
93: public function toNumber(): Type
94: {
95: return new ErrorType();
96: }
97:
98: public function toBitwiseNotType(): Type
99: {
100: return new ErrorType();
101: }
102:
103: public function toAbsoluteNumber(): Type
104: {
105: return new ErrorType();
106: }
107:
108: public function toString(): Type
109: {
110: return new ErrorType();
111: }
112:
113: public function toInteger(): Type
114: {
115: return new ErrorType();
116: }
117:
118: public function toFloat(): Type
119: {
120: return new ErrorType();
121: }
122:
123: public function toArray(): Type
124: {
125: return new ErrorType();
126: }
127:
128: public function toArrayKey(): Type
129: {
130: return new ErrorType();
131: }
132:
133: public function toCoercedArgumentType(bool $strictTypes): Type
134: {
135: return new NullType();
136: }
137:
138: public function isOffsetAccessLegal(): TrinaryLogic
139: {
140: return TrinaryLogic::createYes();
141: }
142:
143: /** void is no set of values; it compares like a value of any kind. */
144: public function getKindMask(): int
145: {
146: return TypeKind::ALL;
147: }
148:
149: public function isNull(): TrinaryLogic
150: {
151: return TrinaryLogic::createNo();
152: }
153:
154: public function isConstantValue(): TrinaryLogic
155: {
156: return TrinaryLogic::createNo();
157: }
158:
159: public function isConstantScalarValue(): TrinaryLogic
160: {
161: return TrinaryLogic::createNo();
162: }
163:
164: public function getConstantScalarTypes(): array
165: {
166: return [];
167: }
168:
169: public function getConstantScalarValues(): array
170: {
171: return [];
172: }
173:
174: public function isTrue(): TrinaryLogic
175: {
176: return TrinaryLogic::createNo();
177: }
178:
179: public function isFalse(): TrinaryLogic
180: {
181: return TrinaryLogic::createNo();
182: }
183:
184: public function isBoolean(): TrinaryLogic
185: {
186: return TrinaryLogic::createNo();
187: }
188:
189: public function isFloat(): TrinaryLogic
190: {
191: return TrinaryLogic::createNo();
192: }
193:
194: public function isInteger(): TrinaryLogic
195: {
196: return TrinaryLogic::createNo();
197: }
198:
199: public function isString(): TrinaryLogic
200: {
201: return TrinaryLogic::createNo();
202: }
203:
204: public function isNumericString(): TrinaryLogic
205: {
206: return TrinaryLogic::createNo();
207: }
208:
209: public function isDecimalIntegerString(): TrinaryLogic
210: {
211: return TrinaryLogic::createNo();
212: }
213:
214: public function isNonEmptyString(): TrinaryLogic
215: {
216: return TrinaryLogic::createNo();
217: }
218:
219: public function isNonFalsyString(): TrinaryLogic
220: {
221: return TrinaryLogic::createNo();
222: }
223:
224: public function isLiteralString(): TrinaryLogic
225: {
226: return TrinaryLogic::createNo();
227: }
228:
229: public function getStringRefinement(): ?int
230: {
231: return null;
232: }
233:
234: public function isLowercaseString(): TrinaryLogic
235: {
236: return TrinaryLogic::createNo();
237: }
238:
239: public function isUppercaseString(): TrinaryLogic
240: {
241: return TrinaryLogic::createNo();
242: }
243:
244: public function isClassString(): TrinaryLogic
245: {
246: return TrinaryLogic::createNo();
247: }
248:
249: public function getClassStringObjectType(): Type
250: {
251: return new ErrorType();
252: }
253:
254: public function getObjectTypeOrClassStringObjectType(): Type
255: {
256: return new ErrorType();
257: }
258:
259: public function isVoid(): TrinaryLogic
260: {
261: return TrinaryLogic::createYes();
262: }
263:
264: public function isScalar(): TrinaryLogic
265: {
266: return TrinaryLogic::createNo();
267: }
268:
269: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
270: {
271: return new BooleanType();
272: }
273:
274: public function traverse(callable $cb): Type
275: {
276: return $this;
277: }
278:
279: public function traverseSimultaneously(Type $right, callable $cb): Type
280: {
281: return $this;
282: }
283:
284: public function arithmeticPower(Type $exponent, PhpVersion $phpVersion): Type
285: {
286: return new ErrorType();
287: }
288:
289: public function getFiniteTypes(): array
290: {
291: return [];
292: }
293:
294: public function toPhpDocNode(): TypeNode
295: {
296: return new IdentifierTypeNode('void');
297: }
298:
299: public function toNativePhpTypeNode(NativeTypePosition $position)
300: {
301: return $position->isVoidAllowed() ? new Identifier('void') : null;
302: }
303:
304: public function hasTemplateOrLateResolvableType(): bool
305: {
306: return false;
307: }
308:
309: public function hasUnresolvedTemplateArgumentType(): bool
310: {
311: return false;
312: }
313:
314: public function toValueSet(): ValueSet
315: {
316: return ValueSet::createInvalid();
317: }
318:
319: public function tryUnion(Type $otherType): ?Type
320: {
321: return null;
322: }
323:
324: public function tryIntersect(Type $otherType): ?Type
325: {
326: return null;
327: }
328:
329: }
330: