| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | use ArrayAccess; |
| 6: | use PhpParser\Node\Identifier; |
| 7: | use PHPStan\Php\PhpVersion; |
| 8: | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; |
| 9: | use PHPStan\PhpDocParser\Ast\Type\TypeNode; |
| 10: | use PHPStan\Reflection\ClassConstantReflection; |
| 11: | use PHPStan\Reflection\ClassMemberAccessAnswerer; |
| 12: | use PHPStan\Reflection\Dummy\DummyClassConstantReflection; |
| 13: | use PHPStan\Reflection\Dummy\DummyMethodReflection; |
| 14: | use PHPStan\Reflection\Dummy\DummyPropertyReflection; |
| 15: | use PHPStan\Reflection\ExtendedMethodReflection; |
| 16: | use PHPStan\Reflection\ExtendedPropertyReflection; |
| 17: | use PHPStan\Reflection\ReflectionProvider; |
| 18: | use PHPStan\Reflection\TrivialParametersAcceptor; |
| 19: | use PHPStan\Reflection\Type\CallbackUnresolvedMethodPrototypeReflection; |
| 20: | use PHPStan\Reflection\Type\CallbackUnresolvedPropertyPrototypeReflection; |
| 21: | use PHPStan\Reflection\Type\UnresolvedMethodPrototypeReflection; |
| 22: | use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection; |
| 23: | use PHPStan\TrinaryLogic; |
| 24: | use PHPStan\Turbo\ShadowedByTurboExtension; |
| 25: | use PHPStan\Type\Accessory\AccessoryArrayListType; |
| 26: | use PHPStan\Type\Accessory\AccessoryDecimalIntegerStringType; |
| 27: | use PHPStan\Type\Accessory\AccessoryLiteralStringType; |
| 28: | use PHPStan\Type\Accessory\AccessoryLowercaseStringType; |
| 29: | use PHPStan\Type\Accessory\AccessoryNonEmptyStringType; |
| 30: | use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; |
| 31: | use PHPStan\Type\Accessory\AccessoryNumericStringType; |
| 32: | use PHPStan\Type\Accessory\AccessoryUppercaseStringType; |
| 33: | use PHPStan\Type\Accessory\OversizedArrayType; |
| 34: | use PHPStan\Type\Constant\ConstantArrayType; |
| 35: | use PHPStan\Type\Constant\ConstantBooleanType; |
| 36: | use PHPStan\Type\Constant\ConstantFloatType; |
| 37: | use PHPStan\Type\Constant\ConstantIntegerType; |
| 38: | use PHPStan\Type\Constant\ConstantStringType; |
| 39: | use PHPStan\Type\Enum\EnumCaseObjectType; |
| 40: | use PHPStan\Type\Generic\TemplateMixedType; |
| 41: | use PHPStan\Type\Generic\TemplateType; |
| 42: | use PHPStan\Type\Traits\NonGeneralizableTypeTrait; |
| 43: | use PHPStan\Type\Traits\NonGenericTypeTrait; |
| 44: | use PHPStan\Type\Traits\OperatorTypeTrait; |
| 45: | use PHPStan\Type\Traits\SubstractableTypeTrait; |
| 46: | use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; |
| 47: | use function get_class; |
| 48: | use function sprintf; |
| 49: | |
| 50: | |
| 51: | #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/MixedType.cpp')] |
| 52: | class MixedType implements CompoundType, SubtractableType |
| 53: | { |
| 54: | |
| 55: | use NonGenericTypeTrait; |
| 56: | use UndecidedComparisonCompoundTypeTrait; |
| 57: | use NonGeneralizableTypeTrait; |
| 58: | use SubstractableTypeTrait; |
| 59: | use OperatorTypeTrait; |
| 60: | |
| 61: | private ?Type $subtractedType; |
| 62: | |
| 63: | |
| 64: | public function __construct( |
| 65: | private bool $isExplicitMixed = false, |
| 66: | ?Type $subtractedType = null, |
| 67: | ) |
| 68: | { |
| 69: | if ($subtractedType instanceof NeverType) { |
| 70: | $subtractedType = null; |
| 71: | } |
| 72: | |
| 73: | $this->subtractedType = $subtractedType; |
| 74: | } |
| 75: | |
| 76: | public function getReferencedClasses(): array |
| 77: | { |
| 78: | return []; |
| 79: | } |
| 80: | |
| 81: | public function getObjectClassNames(): array |
| 82: | { |
| 83: | return []; |
| 84: | } |
| 85: | |
| 86: | public function getObjectClassReflections(): array |
| 87: | { |
| 88: | return []; |
| 89: | } |
| 90: | |
| 91: | public function getArrays(): array |
| 92: | { |
| 93: | return []; |
| 94: | } |
| 95: | |
| 96: | public function getConstantArrays(): array |
| 97: | { |
| 98: | return []; |
| 99: | } |
| 100: | |
| 101: | public function getConstantStrings(): array |
| 102: | { |
| 103: | return []; |
| 104: | } |
| 105: | |
| 106: | public function accepts(Type $type, bool $strictTypes): AcceptsResult |
| 107: | { |
| 108: | return AcceptsResult::createYes(); |
| 109: | } |
| 110: | |
| 111: | public function isSuperTypeOfMixed(MixedType $type): IsSuperTypeOfResult |
| 112: | { |
| 113: | if ($this->subtractedType === null) { |
| 114: | if ($this->isExplicitMixed) { |
| 115: | if ($type->isExplicitMixed) { |
| 116: | return IsSuperTypeOfResult::createYes(); |
| 117: | } |
| 118: | return IsSuperTypeOfResult::createMaybe(); |
| 119: | } |
| 120: | |
| 121: | return IsSuperTypeOfResult::createYes(); |
| 122: | } |
| 123: | |
| 124: | if ($type->subtractedType === null) { |
| 125: | return IsSuperTypeOfResult::createMaybe(); |
| 126: | } |
| 127: | |
| 128: | $isSuperType = $type->subtractedType->isSuperTypeOf($this->subtractedType); |
| 129: | if ($isSuperType->yes()) { |
| 130: | if ($this->isExplicitMixed) { |
| 131: | if ($type->isExplicitMixed) { |
| 132: | return IsSuperTypeOfResult::createYes(); |
| 133: | } |
| 134: | return IsSuperTypeOfResult::createMaybe(); |
| 135: | } |
| 136: | |
| 137: | return IsSuperTypeOfResult::createYes(); |
| 138: | } |
| 139: | |
| 140: | return IsSuperTypeOfResult::createMaybe(); |
| 141: | } |
| 142: | |
| 143: | public function isSuperTypeOf(Type $type): IsSuperTypeOfResult |
| 144: | { |
| 145: | if ($this->subtractedType === null || $type instanceof NeverType) { |
| 146: | return IsSuperTypeOfResult::createYes(); |
| 147: | } |
| 148: | |
| 149: | if ($type instanceof self) { |
| 150: | if ($type->subtractedType === null) { |
| 151: | return IsSuperTypeOfResult::createMaybe(); |
| 152: | } |
| 153: | $isSuperType = $type->subtractedType->isSuperTypeOf($this->subtractedType); |
| 154: | if ($isSuperType->yes()) { |
| 155: | return $isSuperType; |
| 156: | } |
| 157: | |
| 158: | return IsSuperTypeOfResult::createMaybe(); |
| 159: | } |
| 160: | |
| 161: | $result = $this->subtractedType->isSuperTypeOf($type)->negate(); |
| 162: | if ($result->no()) { |
| 163: | return IsSuperTypeOfResult::createNo([ |
| 164: | sprintf( |
| 165: | 'Type %s has already been eliminated from %s.', |
| 166: | $this->subtractedType->describe(VerbosityLevel::precise()), |
| 167: | $this->describe(VerbosityLevel::typeOnly()), |
| 168: | ), |
| 169: | ]); |
| 170: | } |
| 171: | |
| 172: | return $result; |
| 173: | } |
| 174: | |
| 175: | public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type |
| 176: | { |
| 177: | return new self($this->isExplicitMixed); |
| 178: | } |
| 179: | |
| 180: | public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type |
| 181: | { |
| 182: | return new self($this->isExplicitMixed); |
| 183: | } |
| 184: | |
| 185: | public function unsetOffset(Type $offsetType): Type |
| 186: | { |
| 187: | if ($this->subtractedType !== null) { |
| 188: | return new self($this->isExplicitMixed, TypeCombinator::remove($this->subtractedType, new ConstantArrayType([], []))); |
| 189: | } |
| 190: | return $this; |
| 191: | } |
| 192: | |
| 193: | public function getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type |
| 194: | { |
| 195: | return $this->getKeysArray(); |
| 196: | } |
| 197: | |
| 198: | public function getKeysArray(): Type |
| 199: | { |
| 200: | if ($this->isArray()->no()) { |
| 201: | return new ErrorType(); |
| 202: | } |
| 203: | |
| 204: | return new IntersectionType([new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new UnionType([new IntegerType(), new StringType()])), new AccessoryArrayListType()]); |
| 205: | } |
| 206: | |
| 207: | public function getValuesArray(): Type |
| 208: | { |
| 209: | if ($this->isArray()->no()) { |
| 210: | return new ErrorType(); |
| 211: | } |
| 212: | |
| 213: | return new IntersectionType([new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new MixedType($this->isExplicitMixed)), new AccessoryArrayListType()]); |
| 214: | } |
| 215: | |
| 216: | public function chunkArray(Type $lengthType, TrinaryLogic $preserveKeys): Type |
| 217: | { |
| 218: | if ($this->isArray()->no()) { |
| 219: | return new ErrorType(); |
| 220: | } |
| 221: | |
| 222: | return new IntersectionType([new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new MixedType($this->isExplicitMixed)), new AccessoryArrayListType()]); |
| 223: | } |
| 224: | |
| 225: | public function fillKeysArray(Type $valueType): Type |
| 226: | { |
| 227: | if ($this->isArray()->no()) { |
| 228: | return new ErrorType(); |
| 229: | } |
| 230: | |
| 231: | return new ArrayType($this->getIterableValueType()->toArrayKey(), $valueType); |
| 232: | } |
| 233: | |
| 234: | public function flipArray(): Type |
| 235: | { |
| 236: | if ($this->isArray()->no()) { |
| 237: | return new ErrorType(); |
| 238: | } |
| 239: | |
| 240: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 241: | } |
| 242: | |
| 243: | public function intersectKeyArray(Type $otherArraysType): Type |
| 244: | { |
| 245: | if ($this->isArray()->no()) { |
| 246: | return new ErrorType(); |
| 247: | } |
| 248: | |
| 249: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 250: | } |
| 251: | |
| 252: | public function popArray(): Type |
| 253: | { |
| 254: | if ($this->isArray()->no()) { |
| 255: | return new ErrorType(); |
| 256: | } |
| 257: | |
| 258: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 259: | } |
| 260: | |
| 261: | public function reverseArray(TrinaryLogic $preserveKeys): Type |
| 262: | { |
| 263: | if ($this->isArray()->no()) { |
| 264: | return new ErrorType(); |
| 265: | } |
| 266: | |
| 267: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 268: | } |
| 269: | |
| 270: | public function searchArray(Type $needleType, ?TrinaryLogic $strict = null): Type |
| 271: | { |
| 272: | if ($this->isArray()->no()) { |
| 273: | return new ErrorType(); |
| 274: | } |
| 275: | |
| 276: | return new UnionType([new IntegerType(), new StringType(), new ConstantBooleanType(false)]); |
| 277: | } |
| 278: | |
| 279: | public function shiftArray(): Type |
| 280: | { |
| 281: | if ($this->isArray()->no()) { |
| 282: | return new ErrorType(); |
| 283: | } |
| 284: | |
| 285: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 286: | } |
| 287: | |
| 288: | public function shuffleArray(): Type |
| 289: | { |
| 290: | if ($this->isArray()->no()) { |
| 291: | return new ErrorType(); |
| 292: | } |
| 293: | |
| 294: | return new IntersectionType([new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new MixedType($this->isExplicitMixed)), new AccessoryArrayListType()]); |
| 295: | } |
| 296: | |
| 297: | public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type |
| 298: | { |
| 299: | if ($this->isArray()->no()) { |
| 300: | return new ErrorType(); |
| 301: | } |
| 302: | |
| 303: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 304: | } |
| 305: | |
| 306: | public function spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type |
| 307: | { |
| 308: | if ($this->isArray()->no()) { |
| 309: | return new ErrorType(); |
| 310: | } |
| 311: | |
| 312: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 313: | } |
| 314: | |
| 315: | public function truncateListToSize(Type $sizeType): Type |
| 316: | { |
| 317: | if ($this->isArray()->no()) { |
| 318: | return new ErrorType(); |
| 319: | } |
| 320: | |
| 321: | return $this; |
| 322: | } |
| 323: | |
| 324: | public function makeListMaybe(): Type |
| 325: | { |
| 326: | |
| 327: | return $this; |
| 328: | } |
| 329: | |
| 330: | public function mapValueType(callable $cb): Type |
| 331: | { |
| 332: | if ($this->isArray()->no()) { |
| 333: | return new ErrorType(); |
| 334: | } |
| 335: | |
| 336: | return new ArrayType( |
| 337: | new MixedType($this->isExplicitMixed), |
| 338: | $cb(new MixedType($this->isExplicitMixed)), |
| 339: | ); |
| 340: | } |
| 341: | |
| 342: | public function mapKeyType(callable $cb): Type |
| 343: | { |
| 344: | if ($this->isArray()->no()) { |
| 345: | return new ErrorType(); |
| 346: | } |
| 347: | |
| 348: | return new ArrayType( |
| 349: | $cb(new MixedType($this->isExplicitMixed)), |
| 350: | new MixedType($this->isExplicitMixed), |
| 351: | ); |
| 352: | } |
| 353: | |
| 354: | public function makeAllArrayKeysOptional(): Type |
| 355: | { |
| 356: | |
| 357: | return $this; |
| 358: | } |
| 359: | |
| 360: | public function changeKeyCaseArray(?int $case): Type |
| 361: | { |
| 362: | if ($this->isArray()->no()) { |
| 363: | return new ErrorType(); |
| 364: | } |
| 365: | |
| 366: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 367: | } |
| 368: | |
| 369: | public function filterArrayRemovingFalsey(): Type |
| 370: | { |
| 371: | if ($this->isArray()->no()) { |
| 372: | return new ErrorType(); |
| 373: | } |
| 374: | |
| 375: | return new ArrayType(new MixedType($this->isExplicitMixed), new MixedType($this->isExplicitMixed)); |
| 376: | } |
| 377: | |
| 378: | public function isCallable(): TrinaryLogic |
| 379: | { |
| 380: | if ($this->subtractedType !== null) { |
| 381: | if ($this->subtractedType->isSuperTypeOf(new CallableType())->yes()) { |
| 382: | return TrinaryLogic::createNo(); |
| 383: | } |
| 384: | } |
| 385: | |
| 386: | return TrinaryLogic::createMaybe(); |
| 387: | } |
| 388: | |
| 389: | public function getEnumCases(): array |
| 390: | { |
| 391: | return []; |
| 392: | } |
| 393: | |
| 394: | public function getEnumCaseObject(): ?EnumCaseObjectType |
| 395: | { |
| 396: | return null; |
| 397: | } |
| 398: | |
| 399: | public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array |
| 400: | { |
| 401: | return [new TrivialParametersAcceptor()]; |
| 402: | } |
| 403: | |
| 404: | public function equals(Type $type): bool |
| 405: | { |
| 406: | if (get_class($type) !== static::class) { |
| 407: | return false; |
| 408: | } |
| 409: | |
| 410: | if ($this->subtractedType === null) { |
| 411: | if ($type->subtractedType === null) { |
| 412: | return true; |
| 413: | } |
| 414: | |
| 415: | return false; |
| 416: | } |
| 417: | |
| 418: | if ($type->subtractedType === null) { |
| 419: | return false; |
| 420: | } |
| 421: | |
| 422: | return $this->subtractedType->equals($type->subtractedType); |
| 423: | } |
| 424: | |
| 425: | public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult |
| 426: | { |
| 427: | if ($otherType instanceof self && !$otherType instanceof TemplateMixedType) { |
| 428: | return IsSuperTypeOfResult::createYes(); |
| 429: | } |
| 430: | |
| 431: | if ($this->subtractedType !== null) { |
| 432: | $isSuperType = $this->subtractedType->isSuperTypeOf($otherType); |
| 433: | if ($isSuperType->yes()) { |
| 434: | return IsSuperTypeOfResult::createNo(); |
| 435: | } |
| 436: | } |
| 437: | |
| 438: | return IsSuperTypeOfResult::createMaybe(); |
| 439: | } |
| 440: | |
| 441: | public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult |
| 442: | { |
| 443: | $isSuperType = $this->isSuperTypeOf($acceptingType)->toAcceptsResult(); |
| 444: | if ($isSuperType->no()) { |
| 445: | return $isSuperType; |
| 446: | } |
| 447: | return AcceptsResult::createYes(); |
| 448: | } |
| 449: | |
| 450: | public function getTemplateType(string $ancestorClassName, string $templateTypeName): Type |
| 451: | { |
| 452: | return new self(); |
| 453: | } |
| 454: | |
| 455: | public function isObject(): TrinaryLogic |
| 456: | { |
| 457: | if ($this->subtractedType !== null) { |
| 458: | if ($this->subtractedType->isSuperTypeOf(new ObjectWithoutClassType())->yes()) { |
| 459: | return TrinaryLogic::createNo(); |
| 460: | } |
| 461: | } |
| 462: | return TrinaryLogic::createMaybe(); |
| 463: | } |
| 464: | |
| 465: | public function getClassStringType(): Type |
| 466: | { |
| 467: | return new ClassStringType(); |
| 468: | } |
| 469: | |
| 470: | public function isEnum(): TrinaryLogic |
| 471: | { |
| 472: | if ($this->subtractedType !== null) { |
| 473: | if ($this->subtractedType->isSuperTypeOf(new ObjectWithoutClassType())->yes()) { |
| 474: | return TrinaryLogic::createNo(); |
| 475: | } |
| 476: | } |
| 477: | return TrinaryLogic::createMaybe(); |
| 478: | } |
| 479: | |
| 480: | public function canAccessProperties(): TrinaryLogic |
| 481: | { |
| 482: | return TrinaryLogic::createYes(); |
| 483: | } |
| 484: | |
| 485: | public function hasProperty(string $propertyName): TrinaryLogic |
| 486: | { |
| 487: | return TrinaryLogic::createYes(); |
| 488: | } |
| 489: | |
| 490: | public function getProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection |
| 491: | { |
| 492: | return $this->getUnresolvedPropertyPrototype($propertyName, $scope)->getTransformedProperty(); |
| 493: | } |
| 494: | |
| 495: | public function getUnresolvedPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection |
| 496: | { |
| 497: | $property = new DummyPropertyReflection($propertyName); |
| 498: | return new CallbackUnresolvedPropertyPrototypeReflection( |
| 499: | $property, |
| 500: | $property->getDeclaringClass(), |
| 501: | false, |
| 502: | static fn (Type $type): Type => $type, |
| 503: | ); |
| 504: | } |
| 505: | |
| 506: | public function hasInstanceProperty(string $propertyName): TrinaryLogic |
| 507: | { |
| 508: | return TrinaryLogic::createYes(); |
| 509: | } |
| 510: | |
| 511: | public function getInstanceProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection |
| 512: | { |
| 513: | return $this->getUnresolvedInstancePropertyPrototype($propertyName, $scope)->getTransformedProperty(); |
| 514: | } |
| 515: | |
| 516: | public function getUnresolvedInstancePropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection |
| 517: | { |
| 518: | $property = new DummyPropertyReflection($propertyName); |
| 519: | return new CallbackUnresolvedPropertyPrototypeReflection( |
| 520: | $property, |
| 521: | $property->getDeclaringClass(), |
| 522: | false, |
| 523: | static fn (Type $type): Type => $type, |
| 524: | ); |
| 525: | } |
| 526: | |
| 527: | public function hasStaticProperty(string $propertyName): TrinaryLogic |
| 528: | { |
| 529: | return TrinaryLogic::createYes(); |
| 530: | } |
| 531: | |
| 532: | public function getStaticProperty(string $propertyName, ClassMemberAccessAnswerer $scope): ExtendedPropertyReflection |
| 533: | { |
| 534: | return $this->getUnresolvedStaticPropertyPrototype($propertyName, $scope)->getTransformedProperty(); |
| 535: | } |
| 536: | |
| 537: | public function getUnresolvedStaticPropertyPrototype(string $propertyName, ClassMemberAccessAnswerer $scope): UnresolvedPropertyPrototypeReflection |
| 538: | { |
| 539: | $property = new DummyPropertyReflection($propertyName); |
| 540: | return new CallbackUnresolvedPropertyPrototypeReflection( |
| 541: | $property, |
| 542: | $property->getDeclaringClass(), |
| 543: | false, |
| 544: | static fn (Type $type): Type => $type, |
| 545: | ); |
| 546: | } |
| 547: | |
| 548: | public function canCallMethods(): TrinaryLogic |
| 549: | { |
| 550: | return TrinaryLogic::createYes(); |
| 551: | } |
| 552: | |
| 553: | public function hasMethod(string $methodName): TrinaryLogic |
| 554: | { |
| 555: | return TrinaryLogic::createYes(); |
| 556: | } |
| 557: | |
| 558: | public function getMethod(string $methodName, ClassMemberAccessAnswerer $scope): ExtendedMethodReflection |
| 559: | { |
| 560: | return $this->getUnresolvedMethodPrototype($methodName, $scope)->getTransformedMethod(); |
| 561: | } |
| 562: | |
| 563: | public function getUnresolvedMethodPrototype(string $methodName, ClassMemberAccessAnswerer $scope): UnresolvedMethodPrototypeReflection |
| 564: | { |
| 565: | $method = new DummyMethodReflection($methodName); |
| 566: | return new CallbackUnresolvedMethodPrototypeReflection( |
| 567: | $method, |
| 568: | $method->getDeclaringClass(), |
| 569: | false, |
| 570: | static fn (Type $type): Type => $type, |
| 571: | ); |
| 572: | } |
| 573: | |
| 574: | public function canAccessConstants(): TrinaryLogic |
| 575: | { |
| 576: | return TrinaryLogic::createYes(); |
| 577: | } |
| 578: | |
| 579: | public function hasConstant(string $constantName): TrinaryLogic |
| 580: | { |
| 581: | return TrinaryLogic::createYes(); |
| 582: | } |
| 583: | |
| 584: | public function getConstant(string $constantName): ClassConstantReflection |
| 585: | { |
| 586: | return new DummyClassConstantReflection($constantName); |
| 587: | } |
| 588: | |
| 589: | public function isCloneable(): TrinaryLogic |
| 590: | { |
| 591: | return TrinaryLogic::createYes(); |
| 592: | } |
| 593: | |
| 594: | public function describe(VerbosityLevel $level): string |
| 595: | { |
| 596: | return $level->handle( |
| 597: | static fn (): string => 'mixed', |
| 598: | static fn (): string => 'mixed', |
| 599: | fn (): string => 'mixed' . $this->describeSubtractedType($this->subtractedType, $level), |
| 600: | function () use ($level): string { |
| 601: | $description = 'mixed' . $this->describeSubtractedType($this->subtractedType, $level); |
| 602: | |
| 603: | if ($this->isExplicitMixed) { |
| 604: | $description .= '=explicit'; |
| 605: | } else { |
| 606: | $description .= '=implicit'; |
| 607: | } |
| 608: | |
| 609: | return $description; |
| 610: | }, |
| 611: | ); |
| 612: | } |
| 613: | |
| 614: | public function toBoolean(): BooleanType |
| 615: | { |
| 616: | if ($this->subtractedType !== null) { |
| 617: | if ($this->subtractedType->isSuperTypeOf(StaticTypeFactory::falsey())->yes()) { |
| 618: | return new ConstantBooleanType(true); |
| 619: | } |
| 620: | } |
| 621: | |
| 622: | return new BooleanType(); |
| 623: | } |
| 624: | |
| 625: | public function toNumber(): Type |
| 626: | { |
| 627: | return TypeCombinator::union( |
| 628: | $this->toInteger(), |
| 629: | $this->toFloat(), |
| 630: | ); |
| 631: | } |
| 632: | |
| 633: | public function toBitwiseNotType(): Type |
| 634: | { |
| 635: | return new ErrorType(); |
| 636: | } |
| 637: | |
| 638: | public function toGetClassResultType(): Type |
| 639: | { |
| 640: | $isObject = $this->isObject(); |
| 641: | if ($isObject->no()) { |
| 642: | return new ConstantBooleanType(false); |
| 643: | } |
| 644: | |
| 645: | $classString = $this->getClassStringType(); |
| 646: | if ($isObject->yes()) { |
| 647: | return $classString; |
| 648: | } |
| 649: | |
| 650: | return new UnionType([$classString, new ConstantBooleanType(false)]); |
| 651: | } |
| 652: | |
| 653: | public function toClassConstantType(ReflectionProvider $reflectionProvider): Type |
| 654: | { |
| 655: | |
| 656: | |
| 657: | return new ErrorType(); |
| 658: | } |
| 659: | |
| 660: | public function toObjectTypeForInstanceofCheck(): ClassNameToObjectTypeResult |
| 661: | { |
| 662: | return new ClassNameToObjectTypeResult(new MixedType(), false); |
| 663: | } |
| 664: | |
| 665: | public function toObjectTypeForIsACheck(Type $objectOrClassType, bool $allowString, bool $allowSameClass): ClassNameToObjectTypeResult |
| 666: | { |
| 667: | if ($allowString) { |
| 668: | return new ClassNameToObjectTypeResult( |
| 669: | new UnionType([new ObjectWithoutClassType(), new ClassStringType()]), |
| 670: | false, |
| 671: | ); |
| 672: | } |
| 673: | |
| 674: | return new ClassNameToObjectTypeResult(new ObjectWithoutClassType(), false); |
| 675: | } |
| 676: | |
| 677: | public function toAbsoluteNumber(): Type |
| 678: | { |
| 679: | return $this->toNumber()->toAbsoluteNumber(); |
| 680: | } |
| 681: | |
| 682: | public function toInteger(): Type |
| 683: | { |
| 684: | $castsToZero = new UnionType([ |
| 685: | new NullType(), |
| 686: | new ConstantBooleanType(false), |
| 687: | new ConstantIntegerType(0), |
| 688: | new ConstantArrayType([], []), |
| 689: | new StringType(), |
| 690: | new FloatType(), |
| 691: | ]); |
| 692: | if ( |
| 693: | $this->subtractedType !== null |
| 694: | && $this->subtractedType->isSuperTypeOf($castsToZero)->yes() |
| 695: | ) { |
| 696: | return new UnionType([ |
| 697: | IntegerRangeType::fromInterval(null, -1), |
| 698: | IntegerRangeType::fromInterval(1, null), |
| 699: | ]); |
| 700: | } |
| 701: | |
| 702: | return new IntegerType(); |
| 703: | } |
| 704: | |
| 705: | public function toFloat(): Type |
| 706: | { |
| 707: | return new FloatType(); |
| 708: | } |
| 709: | |
| 710: | public function toString(): Type |
| 711: | { |
| 712: | if ($this->subtractedType !== null) { |
| 713: | $castsToEmptyString = new UnionType([ |
| 714: | new NullType(), |
| 715: | new ConstantBooleanType(false), |
| 716: | new ConstantStringType(''), |
| 717: | ]); |
| 718: | if ($this->subtractedType->isSuperTypeOf($castsToEmptyString)->yes()) { |
| 719: | $accessories = [ |
| 720: | new StringType(), |
| 721: | new AccessoryNonEmptyStringType(), |
| 722: | ]; |
| 723: | |
| 724: | $castsToZeroString = new UnionType([ |
| 725: | new ConstantFloatType(0.0), |
| 726: | new ConstantStringType('0'), |
| 727: | new ConstantIntegerType(0), |
| 728: | ]); |
| 729: | if ($this->subtractedType->isSuperTypeOf($castsToZeroString)->yes()) { |
| 730: | $accessories[] = new AccessoryNonFalsyStringType(); |
| 731: | } |
| 732: | return new IntersectionType( |
| 733: | $accessories, |
| 734: | ); |
| 735: | } |
| 736: | } |
| 737: | |
| 738: | return new StringType(); |
| 739: | } |
| 740: | |
| 741: | public function toArray(): Type |
| 742: | { |
| 743: | $mixed = new self($this->isExplicitMixed); |
| 744: | |
| 745: | return new ArrayType($mixed, $mixed); |
| 746: | } |
| 747: | |
| 748: | public function toArrayKey(): Type |
| 749: | { |
| 750: | return new BenevolentUnionType([new IntegerType(), new StringType()]); |
| 751: | } |
| 752: | |
| 753: | public function toCoercedArgumentType(bool $strictTypes): Type |
| 754: | { |
| 755: | return $this; |
| 756: | } |
| 757: | |
| 758: | public function isIterable(): TrinaryLogic |
| 759: | { |
| 760: | if ($this->subtractedType !== null) { |
| 761: | if ($this->subtractedType->isSuperTypeOf(new IterableType(new MixedType(), new MixedType()))->yes()) { |
| 762: | return TrinaryLogic::createNo(); |
| 763: | } |
| 764: | } |
| 765: | |
| 766: | return TrinaryLogic::createMaybe(); |
| 767: | } |
| 768: | |
| 769: | public function isIterableAtLeastOnce(): TrinaryLogic |
| 770: | { |
| 771: | return $this->isIterable(); |
| 772: | } |
| 773: | |
| 774: | public function getArraySize(): Type |
| 775: | { |
| 776: | if ($this->isIterable()->no()) { |
| 777: | return new ErrorType(); |
| 778: | } |
| 779: | |
| 780: | return IntegerRangeType::fromInterval(0, null); |
| 781: | } |
| 782: | |
| 783: | public function getIterableKeyType(): Type |
| 784: | { |
| 785: | return new self($this->isExplicitMixed); |
| 786: | } |
| 787: | |
| 788: | public function getFirstIterableKeyType(): Type |
| 789: | { |
| 790: | return new self($this->isExplicitMixed); |
| 791: | } |
| 792: | |
| 793: | public function getLastIterableKeyType(): Type |
| 794: | { |
| 795: | return new self($this->isExplicitMixed); |
| 796: | } |
| 797: | |
| 798: | public function getIterableValueType(): Type |
| 799: | { |
| 800: | return new self($this->isExplicitMixed); |
| 801: | } |
| 802: | |
| 803: | public function getFirstIterableValueType(): Type |
| 804: | { |
| 805: | return new self($this->isExplicitMixed); |
| 806: | } |
| 807: | |
| 808: | public function getLastIterableValueType(): Type |
| 809: | { |
| 810: | return new self($this->isExplicitMixed); |
| 811: | } |
| 812: | |
| 813: | public function isOffsetAccessible(): TrinaryLogic |
| 814: | { |
| 815: | if ($this->subtractedType !== null) { |
| 816: | $offsetAccessibles = new UnionType([ |
| 817: | new StringType(), |
| 818: | new ArrayType(new MixedType(), new MixedType()), |
| 819: | new ObjectType(ArrayAccess::class), |
| 820: | ]); |
| 821: | |
| 822: | if ($this->subtractedType->isSuperTypeOf($offsetAccessibles)->yes()) { |
| 823: | return TrinaryLogic::createNo(); |
| 824: | } |
| 825: | } |
| 826: | return TrinaryLogic::createMaybe(); |
| 827: | } |
| 828: | |
| 829: | public function isOffsetAccessLegal(): TrinaryLogic |
| 830: | { |
| 831: | if ($this->subtractedType !== null) { |
| 832: | if ($this->subtractedType->isSuperTypeOf(new ObjectWithoutClassType())->yes()) { |
| 833: | return TrinaryLogic::createYes(); |
| 834: | } |
| 835: | } |
| 836: | return TrinaryLogic::createMaybe(); |
| 837: | } |
| 838: | |
| 839: | public function hasOffsetValueType(Type $offsetType): TrinaryLogic |
| 840: | { |
| 841: | if ($this->isOffsetAccessible()->no()) { |
| 842: | return TrinaryLogic::createNo(); |
| 843: | } |
| 844: | |
| 845: | return TrinaryLogic::createMaybe(); |
| 846: | } |
| 847: | |
| 848: | public function getOffsetValueType(Type $offsetType): Type |
| 849: | { |
| 850: | return new self($this->isExplicitMixed); |
| 851: | } |
| 852: | |
| 853: | public function isExplicitMixed(): bool |
| 854: | { |
| 855: | return $this->isExplicitMixed; |
| 856: | } |
| 857: | |
| 858: | public function subtract(Type $type): Type |
| 859: | { |
| 860: | if ($type instanceof self && !$type instanceof TemplateType) { |
| 861: | return new NeverType(); |
| 862: | } |
| 863: | if ($this->subtractedType !== null) { |
| 864: | $type = TypeCombinator::union($this->subtractedType, $type); |
| 865: | } |
| 866: | |
| 867: | return new self($this->isExplicitMixed, $type); |
| 868: | } |
| 869: | |
| 870: | public function getTypeWithoutSubtractedType(): Type |
| 871: | { |
| 872: | return new self($this->isExplicitMixed); |
| 873: | } |
| 874: | |
| 875: | public function changeSubtractedType(?Type $subtractedType): Type |
| 876: | { |
| 877: | return new self($this->isExplicitMixed, $subtractedType); |
| 878: | } |
| 879: | |
| 880: | public function getSubtractedType(): ?Type |
| 881: | { |
| 882: | return $this->subtractedType; |
| 883: | } |
| 884: | |
| 885: | public function traverse(callable $cb): Type |
| 886: | { |
| 887: | return $this; |
| 888: | } |
| 889: | |
| 890: | public function traverseSimultaneously(Type $right, callable $cb): Type |
| 891: | { |
| 892: | return $this; |
| 893: | } |
| 894: | |
| 895: | public function isArray(): TrinaryLogic |
| 896: | { |
| 897: | if ($this->subtractedType !== null) { |
| 898: | if ($this->subtractedType->isSuperTypeOf(new ArrayType(new MixedType(), new MixedType()))->yes()) { |
| 899: | return TrinaryLogic::createNo(); |
| 900: | } |
| 901: | } |
| 902: | |
| 903: | return TrinaryLogic::createMaybe(); |
| 904: | } |
| 905: | |
| 906: | public function isConstantArray(): TrinaryLogic |
| 907: | { |
| 908: | return $this->isArray(); |
| 909: | } |
| 910: | |
| 911: | public function isOversizedArray(): TrinaryLogic |
| 912: | { |
| 913: | if ($this->subtractedType !== null) { |
| 914: | $oversizedArray = new IntersectionType([ |
| 915: | new ArrayType(new MixedType(), new MixedType()), |
| 916: | new OversizedArrayType(), |
| 917: | ]); |
| 918: | |
| 919: | if ($this->subtractedType->isSuperTypeOf($oversizedArray)->yes()) { |
| 920: | return TrinaryLogic::createNo(); |
| 921: | } |
| 922: | } |
| 923: | |
| 924: | return TrinaryLogic::createMaybe(); |
| 925: | } |
| 926: | |
| 927: | public function isList(): TrinaryLogic |
| 928: | { |
| 929: | if ($this->subtractedType !== null) { |
| 930: | $list = new IntersectionType([ |
| 931: | new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new MixedType()), |
| 932: | new AccessoryArrayListType(), |
| 933: | ]); |
| 934: | |
| 935: | if ($this->subtractedType->isSuperTypeOf($list)->yes()) { |
| 936: | return TrinaryLogic::createNo(); |
| 937: | } |
| 938: | } |
| 939: | |
| 940: | return TrinaryLogic::createMaybe(); |
| 941: | } |
| 942: | |
| 943: | public function isNull(): TrinaryLogic |
| 944: | { |
| 945: | if ($this->subtractedType !== null) { |
| 946: | if ($this->subtractedType->isSuperTypeOf(new NullType())->yes()) { |
| 947: | return TrinaryLogic::createNo(); |
| 948: | } |
| 949: | } |
| 950: | |
| 951: | return TrinaryLogic::createMaybe(); |
| 952: | } |
| 953: | |
| 954: | public function isConstantValue(): TrinaryLogic |
| 955: | { |
| 956: | return TrinaryLogic::createNo(); |
| 957: | } |
| 958: | |
| 959: | public function isConstantScalarValue(): TrinaryLogic |
| 960: | { |
| 961: | return TrinaryLogic::createNo(); |
| 962: | } |
| 963: | |
| 964: | public function getConstantScalarTypes(): array |
| 965: | { |
| 966: | return []; |
| 967: | } |
| 968: | |
| 969: | public function getConstantScalarValues(): array |
| 970: | { |
| 971: | return []; |
| 972: | } |
| 973: | |
| 974: | public function isTrue(): TrinaryLogic |
| 975: | { |
| 976: | if ($this->subtractedType !== null) { |
| 977: | if ($this->subtractedType->isSuperTypeOf(new ConstantBooleanType(true))->yes()) { |
| 978: | return TrinaryLogic::createNo(); |
| 979: | } |
| 980: | } |
| 981: | |
| 982: | return TrinaryLogic::createMaybe(); |
| 983: | } |
| 984: | |
| 985: | public function isFalse(): TrinaryLogic |
| 986: | { |
| 987: | if ($this->subtractedType !== null) { |
| 988: | if ($this->subtractedType->isSuperTypeOf(new ConstantBooleanType(false))->yes()) { |
| 989: | return TrinaryLogic::createNo(); |
| 990: | } |
| 991: | } |
| 992: | |
| 993: | return TrinaryLogic::createMaybe(); |
| 994: | } |
| 995: | |
| 996: | public function isBoolean(): TrinaryLogic |
| 997: | { |
| 998: | if ($this->subtractedType !== null) { |
| 999: | if ($this->subtractedType->isSuperTypeOf(new BooleanType())->yes()) { |
| 1000: | return TrinaryLogic::createNo(); |
| 1001: | } |
| 1002: | } |
| 1003: | |
| 1004: | return TrinaryLogic::createMaybe(); |
| 1005: | } |
| 1006: | |
| 1007: | public function isFloat(): TrinaryLogic |
| 1008: | { |
| 1009: | if ($this->subtractedType !== null) { |
| 1010: | if ($this->subtractedType->isSuperTypeOf(new FloatType())->yes()) { |
| 1011: | return TrinaryLogic::createNo(); |
| 1012: | } |
| 1013: | } |
| 1014: | |
| 1015: | return TrinaryLogic::createMaybe(); |
| 1016: | } |
| 1017: | |
| 1018: | public function isInteger(): TrinaryLogic |
| 1019: | { |
| 1020: | if ($this->subtractedType !== null) { |
| 1021: | if ($this->subtractedType->isSuperTypeOf(new IntegerType())->yes()) { |
| 1022: | return TrinaryLogic::createNo(); |
| 1023: | } |
| 1024: | } |
| 1025: | |
| 1026: | return TrinaryLogic::createMaybe(); |
| 1027: | } |
| 1028: | |
| 1029: | public function isString(): TrinaryLogic |
| 1030: | { |
| 1031: | if ($this->subtractedType !== null) { |
| 1032: | if ($this->subtractedType->isSuperTypeOf(new StringType())->yes()) { |
| 1033: | return TrinaryLogic::createNo(); |
| 1034: | } |
| 1035: | } |
| 1036: | return TrinaryLogic::createMaybe(); |
| 1037: | } |
| 1038: | |
| 1039: | public function isNumericString(): TrinaryLogic |
| 1040: | { |
| 1041: | if ($this->subtractedType !== null) { |
| 1042: | $numericString = new IntersectionType([ |
| 1043: | new StringType(), |
| 1044: | new AccessoryNumericStringType(), |
| 1045: | ]); |
| 1046: | |
| 1047: | if ($this->subtractedType->isSuperTypeOf($numericString)->yes()) { |
| 1048: | return TrinaryLogic::createNo(); |
| 1049: | } |
| 1050: | } |
| 1051: | |
| 1052: | return TrinaryLogic::createMaybe(); |
| 1053: | } |
| 1054: | |
| 1055: | public function isDecimalIntegerString(): TrinaryLogic |
| 1056: | { |
| 1057: | if ($this->subtractedType !== null) { |
| 1058: | $decimalIntegerString = new IntersectionType([ |
| 1059: | new StringType(), |
| 1060: | new AccessoryDecimalIntegerStringType(), |
| 1061: | ]); |
| 1062: | |
| 1063: | if ($this->subtractedType->isSuperTypeOf($decimalIntegerString)->yes()) { |
| 1064: | return TrinaryLogic::createNo(); |
| 1065: | } |
| 1066: | } |
| 1067: | |
| 1068: | return TrinaryLogic::createMaybe(); |
| 1069: | } |
| 1070: | |
| 1071: | public function isNonEmptyString(): TrinaryLogic |
| 1072: | { |
| 1073: | if ($this->subtractedType !== null) { |
| 1074: | $nonEmptyString = new IntersectionType([ |
| 1075: | new StringType(), |
| 1076: | new AccessoryNonEmptyStringType(), |
| 1077: | ]); |
| 1078: | |
| 1079: | if ($this->subtractedType->isSuperTypeOf($nonEmptyString)->yes()) { |
| 1080: | return TrinaryLogic::createNo(); |
| 1081: | } |
| 1082: | } |
| 1083: | |
| 1084: | return TrinaryLogic::createMaybe(); |
| 1085: | } |
| 1086: | |
| 1087: | public function isNonFalsyString(): TrinaryLogic |
| 1088: | { |
| 1089: | if ($this->subtractedType !== null) { |
| 1090: | $nonFalsyString = new IntersectionType([ |
| 1091: | new StringType(), |
| 1092: | new AccessoryNonFalsyStringType(), |
| 1093: | ]); |
| 1094: | |
| 1095: | if ($this->subtractedType->isSuperTypeOf($nonFalsyString)->yes()) { |
| 1096: | return TrinaryLogic::createNo(); |
| 1097: | } |
| 1098: | } |
| 1099: | |
| 1100: | return TrinaryLogic::createMaybe(); |
| 1101: | } |
| 1102: | |
| 1103: | public function isLiteralString(): TrinaryLogic |
| 1104: | { |
| 1105: | if ($this->subtractedType !== null) { |
| 1106: | $literalString = new IntersectionType([ |
| 1107: | new StringType(), |
| 1108: | new AccessoryLiteralStringType(), |
| 1109: | ]); |
| 1110: | |
| 1111: | if ($this->subtractedType->isSuperTypeOf($literalString)->yes()) { |
| 1112: | return TrinaryLogic::createNo(); |
| 1113: | } |
| 1114: | } |
| 1115: | |
| 1116: | return TrinaryLogic::createMaybe(); |
| 1117: | } |
| 1118: | |
| 1119: | public function isLowercaseString(): TrinaryLogic |
| 1120: | { |
| 1121: | if ($this->subtractedType !== null) { |
| 1122: | $lowercaseString = new IntersectionType([ |
| 1123: | new StringType(), |
| 1124: | new AccessoryLowercaseStringType(), |
| 1125: | ]); |
| 1126: | |
| 1127: | if ($this->subtractedType->isSuperTypeOf($lowercaseString)->yes()) { |
| 1128: | return TrinaryLogic::createNo(); |
| 1129: | } |
| 1130: | } |
| 1131: | |
| 1132: | return TrinaryLogic::createMaybe(); |
| 1133: | } |
| 1134: | |
| 1135: | public function isUppercaseString(): TrinaryLogic |
| 1136: | { |
| 1137: | if ($this->subtractedType !== null) { |
| 1138: | $uppercaseString = new IntersectionType([ |
| 1139: | new StringType(), |
| 1140: | new AccessoryUppercaseStringType(), |
| 1141: | ]); |
| 1142: | |
| 1143: | if ($this->subtractedType->isSuperTypeOf($uppercaseString)->yes()) { |
| 1144: | return TrinaryLogic::createNo(); |
| 1145: | } |
| 1146: | } |
| 1147: | |
| 1148: | return TrinaryLogic::createMaybe(); |
| 1149: | } |
| 1150: | |
| 1151: | public function isClassString(): TrinaryLogic |
| 1152: | { |
| 1153: | if ($this->subtractedType !== null) { |
| 1154: | if ($this->subtractedType->isSuperTypeOf(new StringType())->yes()) { |
| 1155: | return TrinaryLogic::createNo(); |
| 1156: | } |
| 1157: | if ($this->subtractedType->isSuperTypeOf(new ClassStringType())->yes()) { |
| 1158: | return TrinaryLogic::createNo(); |
| 1159: | } |
| 1160: | } |
| 1161: | |
| 1162: | return TrinaryLogic::createMaybe(); |
| 1163: | } |
| 1164: | |
| 1165: | public function getClassStringObjectType(): Type |
| 1166: | { |
| 1167: | if (!$this->isClassString()->no()) { |
| 1168: | return new ObjectWithoutClassType(); |
| 1169: | } |
| 1170: | |
| 1171: | return new ErrorType(); |
| 1172: | } |
| 1173: | |
| 1174: | public function getObjectTypeOrClassStringObjectType(): Type |
| 1175: | { |
| 1176: | $objectOrClass = new UnionType([ |
| 1177: | new ObjectWithoutClassType(), |
| 1178: | new ClassStringType(), |
| 1179: | ]); |
| 1180: | if (!$this->isSuperTypeOf($objectOrClass)->no()) { |
| 1181: | return new ObjectWithoutClassType(); |
| 1182: | } |
| 1183: | |
| 1184: | return new ErrorType(); |
| 1185: | } |
| 1186: | |
| 1187: | public function isVoid(): TrinaryLogic |
| 1188: | { |
| 1189: | if ($this->subtractedType !== null) { |
| 1190: | if ($this->subtractedType->isSuperTypeOf(new VoidType())->yes()) { |
| 1191: | return TrinaryLogic::createNo(); |
| 1192: | } |
| 1193: | } |
| 1194: | |
| 1195: | return TrinaryLogic::createMaybe(); |
| 1196: | } |
| 1197: | |
| 1198: | public function isScalar(): TrinaryLogic |
| 1199: | { |
| 1200: | if ($this->subtractedType !== null) { |
| 1201: | if ($this->subtractedType->isSuperTypeOf(new UnionType([new BooleanType(), new FloatType(), new IntegerType(), new StringType()]))->yes()) { |
| 1202: | return TrinaryLogic::createNo(); |
| 1203: | } |
| 1204: | } |
| 1205: | |
| 1206: | return TrinaryLogic::createMaybe(); |
| 1207: | } |
| 1208: | |
| 1209: | public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType |
| 1210: | { |
| 1211: | return new BooleanType(); |
| 1212: | } |
| 1213: | |
| 1214: | public function tryRemove(Type $typeToRemove): ?Type |
| 1215: | { |
| 1216: | |
| 1217: | |
| 1218: | |
| 1219: | if ($this->isSuperTypeOf($typeToRemove)->no()) { |
| 1220: | return null; |
| 1221: | } |
| 1222: | |
| 1223: | return $this->subtract($typeToRemove); |
| 1224: | } |
| 1225: | |
| 1226: | public function arithmeticPower(Type $exponent, PhpVersion $phpVersion): Type |
| 1227: | { |
| 1228: | return new BenevolentUnionType([ |
| 1229: | new FloatType(), |
| 1230: | new IntegerType(), |
| 1231: | ]); |
| 1232: | } |
| 1233: | |
| 1234: | public function getFiniteTypes(): array |
| 1235: | { |
| 1236: | return []; |
| 1237: | } |
| 1238: | |
| 1239: | public function toPhpDocNode(): TypeNode |
| 1240: | { |
| 1241: | return new IdentifierTypeNode('mixed'); |
| 1242: | } |
| 1243: | |
| 1244: | public function toNativePhpTypeNode(NativeTypePosition $position) |
| 1245: | { |
| 1246: | if (!$this->isExplicitMixed || !$position->isMixedAllowed()) { |
| 1247: | return null; |
| 1248: | } |
| 1249: | |
| 1250: | return new Identifier('mixed'); |
| 1251: | } |
| 1252: | |
| 1253: | public function hasTemplateOrLateResolvableType(): bool |
| 1254: | { |
| 1255: | return false; |
| 1256: | } |
| 1257: | |
| 1258: | public function toValueSet(): ValueSet |
| 1259: | { |
| 1260: | return ValueSet::createUnknown($this); |
| 1261: | } |
| 1262: | |
| 1263: | } |
| 1264: | |