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\ReflectionProvider;
13: use PHPStan\Reflection\Type\UnresolvedMethodPrototypeReflection;
14: use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
15: use PHPStan\ShouldNotHappenException;
16: use PHPStan\TrinaryLogic;
17: use PHPStan\Turbo\ShadowedByTurboExtension;
18: use PHPStan\Type\Enum\EnumCaseObjectType;
19: use PHPStan\Type\Generic\TemplateType;
20: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
21: use PHPStan\Type\Traits\NonGenericTypeTrait;
22: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
23: use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
24: use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
25:
26: /** @api */
27: #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/NeverType.cpp')]
28: class NeverType implements CompoundType
29: {
30:
31: use UndecidedBooleanTypeTrait;
32: use NonGenericTypeTrait;
33: use UndecidedComparisonCompoundTypeTrait;
34: use NonRemoveableTypeTrait;
35: use NonGeneralizableTypeTrait;
36:
37: /** @api */
38: public function __construct(private bool $isExplicit = false, private ?string $reason = null)
39: {
40: }
41:
42: public function isExplicit(): bool
43: {
44: return $this->isExplicit;
45: }
46:
47: public function getReason(): ?string
48: {
49: return $this->reason;
50: }
51:
52: public function getReferencedClasses(): array
53: {
54: return [];
55: }
56:
57: public function getArrays(): array
58: {
59: return [];
60: }
61:
62: public function getConstantArrays(): array
63: {
64: return [];
65: }
66:
67: public function getObjectClassNames(): array
68: {
69: return [];
70: }
71:
72: public function getObjectClassReflections(): array
73: {
74: return [];
75: }
76:
77: public function getConstantStrings(): array
78: {
79: return [];
80: }
81:
82: public function accepts(Type $type, bool $strictTypes): AcceptsResult
83: {
84: return AcceptsResult::createYes();
85: }
86:
87: public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
88: {
89: if ($type instanceof self) {
90: return IsSuperTypeOfResult::createYes();
91: }
92:
93: if ($type instanceof TemplateType) {
94: return IsSuperTypeOfResult::createMaybe();
95: }
96:
97: return IsSuperTypeOfResult::createNo();
98: }
99:
100: public function equals(Type $type): bool
101: {
102: return $type instanceof self;
103: }
104:
105: public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
106: {
107: return IsSuperTypeOfResult::createYes();
108: }
109:
110: public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
111: {
112: return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
113: }
114:
115: public function describe(VerbosityLevel $level): string
116: {
117: return '*NEVER*';
118: }
119:
120: public function getTemplateType(string $ancestorClassName, string $templateTypeName): Type
121: {
122: return new NeverType();
123: }
124:
125: public function isObject(): TrinaryLogic
126: {
127: return TrinaryLogic::createNo();
128: }
129:
130: public function getClassStringType(): Type
131: {
132: return new NeverType();
133: }
134:
135: public function isEnum(): TrinaryLogic
136: {
137: return TrinaryLogic::createNo();
138: }
139:
140: public function canAccessProperties(): TrinaryLogic
141: {
142: return TrinaryLogic::createYes();
143: }
144:
145: public function hasProperty(string $propertyName): TrinaryLogic
146: {
147: return TrinaryLogic::createNo();
148: }
149:
150: public function getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
151: {
152: throw new ShouldNotHappenException();
153: }
154:
155: public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
156: {
157: throw new ShouldNotHappenException();
158: }
159:
160: public function hasInstanceProperty(string $propertyName): TrinaryLogic
161: {
162: return TrinaryLogic::createNo();
163: }
164:
165: public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
166: {
167: throw new ShouldNotHappenException();
168: }
169:
170: public function getUnresolvedInstancePropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
171: {
172: throw new ShouldNotHappenException();
173: }
174:
175: public function hasStaticProperty(string $propertyName): TrinaryLogic
176: {
177: return TrinaryLogic::createNo();
178: }
179:
180: public function getStaticProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection
181: {
182: throw new ShouldNotHappenException();
183: }
184:
185: public function getUnresolvedStaticPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection
186: {
187: throw new ShouldNotHappenException();
188: }
189:
190: public function canCallMethods(): TrinaryLogic
191: {
192: return TrinaryLogic::createYes();
193: }
194:
195: public function hasMethod(string $methodName): TrinaryLogic
196: {
197: return TrinaryLogic::createNo();
198: }
199:
200: public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ExtendedMethodReflection
201: {
202: throw new ShouldNotHappenException();
203: }
204:
205: public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection
206: {
207: throw new ShouldNotHappenException();
208: }
209:
210: public function canAccessConstants(): TrinaryLogic
211: {
212: return TrinaryLogic::createYes();
213: }
214:
215: public function hasConstant(string $constantName): TrinaryLogic
216: {
217: return TrinaryLogic::createNo();
218: }
219:
220: public function getConstant(string $constantName): ClassConstantReflection
221: {
222: throw new ShouldNotHappenException();
223: }
224:
225: public function isIterable(): TrinaryLogic
226: {
227: return TrinaryLogic::createYes();
228: }
229:
230: public function isIterableAtLeastOnce(): TrinaryLogic
231: {
232: return TrinaryLogic::createMaybe();
233: }
234:
235: public function getArraySize(): Type
236: {
237: return new NeverType();
238: }
239:
240: public function getIterableKeyType(): Type
241: {
242: return new NeverType();
243: }
244:
245: public function getFirstIterableKeyType(): Type
246: {
247: return new NeverType();
248: }
249:
250: public function getLastIterableKeyType(): Type
251: {
252: return new NeverType();
253: }
254:
255: public function getIterableValueType(): Type
256: {
257: return new NeverType();
258: }
259:
260: public function getFirstIterableValueType(): Type
261: {
262: return new NeverType();
263: }
264:
265: public function getLastIterableValueType(): Type
266: {
267: return new NeverType();
268: }
269:
270: public function isArray(): TrinaryLogic
271: {
272: return TrinaryLogic::createNo();
273: }
274:
275: public function isConstantArray(): TrinaryLogic
276: {
277: return TrinaryLogic::createNo();
278: }
279:
280: public function isOversizedArray(): TrinaryLogic
281: {
282: return TrinaryLogic::createNo();
283: }
284:
285: public function isList(): TrinaryLogic
286: {
287: return TrinaryLogic::createNo();
288: }
289:
290: public function isOffsetAccessible(): TrinaryLogic
291: {
292: return TrinaryLogic::createYes();
293: }
294:
295: public function isOffsetAccessLegal(): TrinaryLogic
296: {
297: return TrinaryLogic::createYes();
298: }
299:
300: public function hasOffsetValueType(Type $offsetType): TrinaryLogic
301: {
302: return TrinaryLogic::createYes();
303: }
304:
305: public function getOffsetValueType(Type $offsetType): Type
306: {
307: return new NeverType();
308: }
309:
310: public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
311: {
312: return new ErrorType();
313: }
314:
315: public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
316: {
317: return new ErrorType();
318: }
319:
320: public function unsetOffset(Type $offsetType): Type
321: {
322: return new NeverType();
323: }
324:
325: public function getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type
326: {
327: return $this->getKeysArray();
328: }
329:
330: public function getKeysArray(): Type
331: {
332: return new NeverType();
333: }
334:
335: public function getValuesArray(): Type
336: {
337: return new NeverType();
338: }
339:
340: public function chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type
341: {
342: return new NeverType();
343: }
344:
345: public function fillKeysArray(Type $valueType): Type
346: {
347: return new NeverType();
348: }
349:
350: public function flipArray(): Type
351: {
352: return new NeverType();
353: }
354:
355: public function intersectKeyArray(Type $otherArraysType): Type
356: {
357: return new NeverType();
358: }
359:
360: public function popArray(): Type
361: {
362: return new NeverType();
363: }
364:
365: public function reverseArray(TrinaryLogic $preserveKeys): Type
366: {
367: return new NeverType();
368: }
369:
370: public function searchArray(Type $needleType, ?TrinaryLogic $strict = null): Type
371: {
372: return new NeverType();
373: }
374:
375: public function shiftArray(): Type
376: {
377: return new NeverType();
378: }
379:
380: public function shuffleArray(): Type
381: {
382: return new NeverType();
383: }
384:
385: public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
386: {
387: return new NeverType();
388: }
389:
390: public function spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type
391: {
392: return new NeverType();
393: }
394:
395: public function truncateListToSize(Type $sizeType): Type
396: {
397: return new NeverType();
398: }
399:
400: public function makeListMaybe(): Type
401: {
402: return new NeverType();
403: }
404:
405: public function mapValueType(callable $cb): Type
406: {
407: return new NeverType();
408: }
409:
410: public function mapKeyType(callable $cb): Type
411: {
412: return new NeverType();
413: }
414:
415: public function makeAllArrayKeysOptional(): Type
416: {
417: return new NeverType();
418: }
419:
420: public function changeKeyCaseArray(?int $case): Type
421: {
422: return new NeverType();
423: }
424:
425: public function filterArrayRemovingFalsey(): Type
426: {
427: return new NeverType();
428: }
429:
430: public function isCallable(): TrinaryLogic
431: {
432: return TrinaryLogic::createNo();
433: }
434:
435: public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
436: {
437: throw new ShouldNotHappenException();
438: }
439:
440: public function isCloneable(): TrinaryLogic
441: {
442: return TrinaryLogic::createYes();
443: }
444:
445: public function toNumber(): Type
446: {
447: return $this;
448: }
449:
450: public function toBitwiseNotType(): Type
451: {
452: return $this;
453: }
454:
455: public function toGetClassResultType(): Type
456: {
457: return $this;
458: }
459:
460: public function toClassConstantType(ReflectionProvider $reflectionProvider): Type
461: {
462: return $this;
463: }
464:
465: public function toObjectTypeForInstanceofCheck(): ClassNameToObjectTypeResult
466: {
467: return new ClassNameToObjectTypeResult($this, false);
468: }
469:
470: public function toObjectTypeForIsACheck(Type $objectOrClassType, bool $allowString, bool $allowSameClass): ClassNameToObjectTypeResult
471: {
472: return new ClassNameToObjectTypeResult($this, false);
473: }
474:
475: public function toAbsoluteNumber(): Type
476: {
477: return $this;
478: }
479:
480: public function toString(): Type
481: {
482: return $this;
483: }
484:
485: public function toInteger(): Type
486: {
487: return $this;
488: }
489:
490: public function toFloat(): Type
491: {
492: return $this;
493: }
494:
495: public function toArray(): Type
496: {
497: return $this;
498: }
499:
500: public function toArrayKey(): Type
501: {
502: return $this;
503: }
504:
505: public function toCoercedArgumentType(bool $strictTypes): Type
506: {
507: return $this;
508: }
509:
510: public function traverse(callable $cb): Type
511: {
512: return $this;
513: }
514:
515: public function traverseSimultaneously(Type $right, callable $cb): Type
516: {
517: return $this;
518: }
519:
520: public function isNull(): TrinaryLogic
521: {
522: return TrinaryLogic::createNo();
523: }
524:
525: public function isConstantValue(): TrinaryLogic
526: {
527: return TrinaryLogic::createNo();
528: }
529:
530: public function isConstantScalarValue(): TrinaryLogic
531: {
532: return TrinaryLogic::createNo();
533: }
534:
535: public function getConstantScalarTypes(): array
536: {
537: return [];
538: }
539:
540: public function getConstantScalarValues(): array
541: {
542: return [];
543: }
544:
545: public function isTrue(): TrinaryLogic
546: {
547: return TrinaryLogic::createNo();
548: }
549:
550: public function isFalse(): TrinaryLogic
551: {
552: return TrinaryLogic::createNo();
553: }
554:
555: public function isBoolean(): TrinaryLogic
556: {
557: return TrinaryLogic::createNo();
558: }
559:
560: public function isFloat(): TrinaryLogic
561: {
562: return TrinaryLogic::createNo();
563: }
564:
565: public function isInteger(): TrinaryLogic
566: {
567: return TrinaryLogic::createNo();
568: }
569:
570: public function isString(): TrinaryLogic
571: {
572: return TrinaryLogic::createNo();
573: }
574:
575: public function isNumericString(): TrinaryLogic
576: {
577: return TrinaryLogic::createNo();
578: }
579:
580: public function isDecimalIntegerString(): TrinaryLogic
581: {
582: return TrinaryLogic::createNo();
583: }
584:
585: public function isNonEmptyString(): TrinaryLogic
586: {
587: return TrinaryLogic::createNo();
588: }
589:
590: public function isNonFalsyString(): TrinaryLogic
591: {
592: return TrinaryLogic::createNo();
593: }
594:
595: public function isLiteralString(): TrinaryLogic
596: {
597: return TrinaryLogic::createNo();
598: }
599:
600: public function isLowercaseString(): TrinaryLogic
601: {
602: return TrinaryLogic::createNo();
603: }
604:
605: public function isUppercaseString(): TrinaryLogic
606: {
607: return TrinaryLogic::createNo();
608: }
609:
610: public function isClassString(): TrinaryLogic
611: {
612: return TrinaryLogic::createNo();
613: }
614:
615: public function getClassStringObjectType(): Type
616: {
617: return new ErrorType();
618: }
619:
620: public function getObjectTypeOrClassStringObjectType(): Type
621: {
622: return new ErrorType();
623: }
624:
625: public function isVoid(): TrinaryLogic
626: {
627: return TrinaryLogic::createNo();
628: }
629:
630: public function isScalar(): TrinaryLogic
631: {
632: return TrinaryLogic::createNo();
633: }
634:
635: public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
636: {
637: return new BooleanType();
638: }
639:
640: public function getEnumCases(): array
641: {
642: return [];
643: }
644:
645: public function getEnumCaseObject(): ?EnumCaseObjectType
646: {
647: return null;
648: }
649:
650: public function exponentiate(Type $exponent): Type
651: {
652: return $this;
653: }
654:
655: public function getFiniteTypes(): array
656: {
657: return [];
658: }
659:
660: public function toPhpDocNode(): TypeNode
661: {
662: return new IdentifierTypeNode('never');
663: }
664:
665: public function hasTemplateOrLateResolvableType(): bool
666: {
667: return false;
668: }
669:
670: }
671: