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