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