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