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