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\Reflection\ClassConstantReflection;
9: use PHPStan\Reflection\ClassMemberAccessAnswerer;
10: use PHPStan\Reflection\ExtendedMethodReflection;
11: use PHPStan\Reflection\ExtendedPropertyReflection;
12: use PHPStan\Reflection\Type\UnresolvedMethodPrototypeReflection;
13: use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
14: use PHPStan\ShouldNotHappenException;
15: use PHPStan\TrinaryLogic;
16: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
17: use PHPStan\Type\Traits\NonGenericTypeTrait;
18: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
19: use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
20: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
21:
22: /** @api */
23: class NeverType implements CompoundType
24: {
25:
26: use UndecidedBooleanTypeTrait;
27: use NonGenericTypeTrait;
28: use UndecidedComparisonCompoundTypeTrait;
29: use NonRemoveableTypeTrait;
30: use NonGeneralizableTypeTrait;
31:
32: /** @api */
33: public function __construct(private bool $isExplicit = false)
34: {
35: }
36:
37: public function isExplicit(): bool
38: {
39: return $this->isExplicit;
40: }
41:
42: public function getReferencedClasses(): array
43: {
44: return [];
45: }
46:
47: public function getArrays(): array
48: {
49: return [];
50: }
51:
52: public function getConstantArrays(): array
53: {
54: return [];
55: }
56:
57: public function getObjectClassNames(): array
58: {
59: return [];
60: }
61:
62: public function getObjectClassReflections(): array
63: {
64: return [];
65: }
66:
67: public function getConstantStrings(): array
68: {
69: return [];
70: }
71:
72: public function accepts(Type $type, bool $strictTypes): AcceptsResult
73: {
74: return AcceptsResult::createYes();
75: }
76:
77: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
78: {
79: if ($type instanceof self) {
80: return IsSuperTypeOfResult::createYes();
81: }
82:
83: return IsSuperTypeOfResult::createNo();
84: }
85:
86: public function equals(Type $type): bool
87: {
88: return $type instanceof self;
89: }
90:
91: public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
92: {
93: return IsSuperTypeOfResult::createYes();
94: }
95:
96: public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
97: {
98: return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
99: }
100:
101: public function describe(VerbosityLevel $level): string
102: {
103: return '*NEVER*';
104: }
105:
106: public function getTemplateType(string $ancestorClassName, string $templateTypeName): Type
107: {
108: return new NeverType();
109: }
110:
111: public function isObject(): TrinaryLogic
112: {
113: return TrinaryLogic::createNo();
114: }
115:
116: public function isEnum(): TrinaryLogic
117: {
118: return TrinaryLogic::createNo();
119: }
120:
121: public function canAccessProperties(): TrinaryLogic
122: {
123: return TrinaryLogic::createYes();
124: }
125:
126: public function hasProperty(string $propertyName): TrinaryLogic
127: {
128: return TrinaryLogic::createNo();
129: }
130:
131: public function getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
132: {
133: throw new ShouldNotHappenException();
134: }
135:
136: public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
137: {
138: throw new ShouldNotHappenException();
139: }
140:
141: public function canCallMethods(): TrinaryLogic
142: {
143: return TrinaryLogic::createYes();
144: }
145:
146: public function hasMethod(string $methodName): TrinaryLogic
147: {
148: return TrinaryLogic::createNo();
149: }
150:
151: public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ExtendedMethodReflection
152: {
153: throw new ShouldNotHappenException();
154: }
155:
156: public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection
157: {
158: throw new ShouldNotHappenException();
159: }
160:
161: public function canAccessConstants(): TrinaryLogic
162: {
163: return TrinaryLogic::createYes();
164: }
165:
166: public function hasConstant(string $constantName): TrinaryLogic
167: {
168: return TrinaryLogic::createNo();
169: }
170:
171: public function getConstant(string $constantName): ClassConstantReflection
172: {
173: throw new ShouldNotHappenException();
174: }
175:
176: public function isIterable(): TrinaryLogic
177: {
178: return TrinaryLogic::createYes();
179: }
180:
181: public function isIterableAtLeastOnce(): TrinaryLogic
182: {
183: return TrinaryLogic::createMaybe();
184: }
185:
186: public function getArraySize(): Type
187: {
188: return new NeverType();
189: }
190:
191: public function getIterableKeyType(): Type
192: {
193: return new NeverType();
194: }
195:
196: public function getFirstIterableKeyType(): Type
197: {
198: return new NeverType();
199: }
200:
201: public function getLastIterableKeyType(): Type
202: {
203: return new NeverType();
204: }
205:
206: public function getIterableValueType(): Type
207: {
208: return new NeverType();
209: }
210:
211: public function getFirstIterableValueType(): Type
212: {
213: return new NeverType();
214: }
215:
216: public function getLastIterableValueType(): Type
217: {
218: return new NeverType();
219: }
220:
221: public function isArray(): TrinaryLogic
222: {
223: return TrinaryLogic::createNo();
224: }
225:
226: public function isConstantArray(): TrinaryLogic
227: {
228: return TrinaryLogic::createNo();
229: }
230:
231: public function isOversizedArray(): TrinaryLogic
232: {
233: return TrinaryLogic::createNo();
234: }
235:
236: public function isList(): TrinaryLogic
237: {
238: return TrinaryLogic::createNo();
239: }
240:
241: public function isOffsetAccessible(): TrinaryLogic
242: {
243: return TrinaryLogic::createYes();
244: }
245:
246: public function isOffsetAccessLegal(): TrinaryLogic
247: {
248: return TrinaryLogic::createYes();
249: }
250:
251: public function hasOffsetValueType(Type $offsetType): TrinaryLogic
252: {
253: return TrinaryLogic::createYes();
254: }
255:
256: public function getOffsetValueType(Type $offsetType): Type
257: {
258: return new NeverType();
259: }
260:
261: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
262: {
263: return new ErrorType();
264: }
265:
266: public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
267: {
268: return new ErrorType();
269: }
270:
271: public function unsetOffset(Type $offsetType): Type
272: {
273: return new NeverType();
274: }
275:
276: public function getKeysArray(): Type
277: {
278: return new NeverType();
279: }
280:
281: public function getValuesArray(): Type
282: {
283: return new NeverType();
284: }
285:
286: public function chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type
287: {
288: return new NeverType();
289: }
290:
291: public function fillKeysArray(Type $valueType): Type
292: {
293: return new NeverType();
294: }
295:
296: public function flipArray(): Type
297: {
298: return new NeverType();
299: }
300:
301: public function intersectKeyArray(Type $otherArraysType): Type
302: {
303: return new NeverType();
304: }
305:
306: public function popArray(): Type
307: {
308: return new NeverType();
309: }
310:
311: public function reverseArray(TrinaryLogic $preserveKeys): Type
312: {
313: return new NeverType();
314: }
315:
316: public function searchArray(Type $needleType): Type
317: {
318: return new NeverType();
319: }
320:
321: public function shiftArray(): Type
322: {
323: return new NeverType();
324: }
325:
326: public function shuffleArray(): Type
327: {
328: return new NeverType();
329: }
330:
331: public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
332: {
333: return new NeverType();
334: }
335:
336: public function isCallable(): TrinaryLogic
337: {
338: return TrinaryLogic::createNo();
339: }
340:
341: public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
342: {
343: throw new ShouldNotHappenException();
344: }
345:
346: public function isCloneable(): TrinaryLogic
347: {
348: return TrinaryLogic::createYes();
349: }
350:
351: public function toNumber(): Type
352: {
353: return $this;
354: }
355:
356: public function toAbsoluteNumber(): Type
357: {
358: return $this;
359: }
360:
361: public function toString(): Type
362: {
363: return $this;
364: }
365:
366: public function toInteger(): Type
367: {
368: return $this;
369: }
370:
371: public function toFloat(): Type
372: {
373: return $this;
374: }
375:
376: public function toArray(): Type
377: {
378: return $this;
379: }
380:
381: public function toArrayKey(): Type
382: {
383: return $this;
384: }
385:
386: public function traverse(callable $cb): Type
387: {
388: return $this;
389: }
390:
391: public function traverseSimultaneously(Type $right, callable $cb): Type
392: {
393: return $this;
394: }
395:
396: public function isNull(): TrinaryLogic
397: {
398: return TrinaryLogic::createNo();
399: }
400:
401: public function isConstantValue(): TrinaryLogic
402: {
403: return TrinaryLogic::createNo();
404: }
405:
406: public function isConstantScalarValue(): TrinaryLogic
407: {
408: return TrinaryLogic::createNo();
409: }
410:
411: public function getConstantScalarTypes(): array
412: {
413: return [];
414: }
415:
416: public function getConstantScalarValues(): array
417: {
418: return [];
419: }
420:
421: public function isTrue(): TrinaryLogic
422: {
423: return TrinaryLogic::createNo();
424: }
425:
426: public function isFalse(): TrinaryLogic
427: {
428: return TrinaryLogic::createNo();
429: }
430:
431: public function isBoolean(): TrinaryLogic
432: {
433: return TrinaryLogic::createNo();
434: }
435:
436: public function isFloat(): TrinaryLogic
437: {
438: return TrinaryLogic::createNo();
439: }
440:
441: public function isInteger(): TrinaryLogic
442: {
443: return TrinaryLogic::createNo();
444: }
445:
446: public function isString(): TrinaryLogic
447: {
448: return TrinaryLogic::createNo();
449: }
450:
451: public function isNumericString(): TrinaryLogic
452: {
453: return TrinaryLogic::createNo();
454: }
455:
456: public function isNonEmptyString(): TrinaryLogic
457: {
458: return TrinaryLogic::createNo();
459: }
460:
461: public function isNonFalsyString(): TrinaryLogic
462: {
463: return TrinaryLogic::createNo();
464: }
465:
466: public function isLiteralString(): TrinaryLogic
467: {
468: return TrinaryLogic::createNo();
469: }
470:
471: public function isLowercaseString(): TrinaryLogic
472: {
473: return TrinaryLogic::createNo();
474: }
475:
476: public function isClassString(): TrinaryLogic
477: {
478: return TrinaryLogic::createNo();
479: }
480:
481: public function getClassStringObjectType(): Type
482: {
483: return new ErrorType();
484: }
485:
486: public function getObjectTypeOrClassStringObjectType(): Type
487: {
488: return new ErrorType();
489: }
490:
491: public function isVoid(): TrinaryLogic
492: {
493: return TrinaryLogic::createNo();
494: }
495:
496: public function isScalar(): TrinaryLogic
497: {
498: return TrinaryLogic::createNo();
499: }
500:
501: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
502: {
503: return new BooleanType();
504: }
505:
506: public function getEnumCases(): array
507: {
508: return [];
509: }
510:
511: public function exponentiate(Type $exponent): Type
512: {
513: return $this;
514: }
515:
516: public function getFiniteTypes(): array
517: {
518: return [];
519: }
520:
521: public function toPhpDocNode(): TypeNode
522: {
523: return new IdentifierTypeNode('never');
524: }
525:
526: }
527: