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