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