| Methods |
public
static
|
fromInterval(?int $min, ?int $max, int $shift = 0): Type
|
#
|
protected
static
|
isDisjoint(?int $minA, ?int $maxA, ?int $minB, ?int $maxB, bool $touchingIsDisjoint = true): bool
|
#
|
public
static
|
createAllSmallerThan(int|float $value): Type
Return the range of integers smaller than the given value
Return the range of integers smaller than the given value
|
#
|
public
static
|
createAllSmallerThanOrEqualTo(int|float $value): Type
Return the range of integers smaller than or equal to the given value
Return the range of integers smaller than or equal to the given value
|
#
|
public
static
|
createAllGreaterThan(int|float $value): Type
Return the range of integers greater than the given value
Return the range of integers greater than the given value
|
#
|
public
static
|
createAllGreaterThanOrEqualTo(int|float $value): Type
Return the range of integers greater than or equal to the given value
Return the range of integers greater than or equal to the given value
|
#
|
public
|
toNumberSet(): NumberSet
The intervals of the numbers this type holds, or null when it can hold
anything but an int or a float. Unlike toNumber() it converts nothing:
call it on toNumber() for the numbers an operand stands for.
The intervals of the numbers this type holds, or null when it can hold
anything but an int or a float. Unlike toNumber() it converts nothing:
call it on toNumber() for the numbers an operand stands for.
Overrides
Implements
|
#
|
public
|
getMin(): ?int
|
#
|
public
|
getMax(): ?int
|
#
|
public
|
describe(VerbosityLevel $level): string
|
#
|
public
|
shift(int $amount): Type
|
#
|
public
|
accepts(Type $type, bool $strictTypes): AcceptsResult
Unlike isSuperTypeOf(), accepts() takes into account PHP's implicit type coercion.
With $strictTypes = false, int is accepted by float, and Stringable objects are
accepted by string.
Unlike isSuperTypeOf(), accepts() takes into account PHP's implicit type coercion.
With $strictTypes = false, int is accepted by float, and Stringable objects are
accepted by string.
Implements
|
#
|
public
|
isSuperTypeOf(Type $type): IsSuperTypeOfResult
"Does every value of $type belong to $this type?"
"Does every value of $type belong to $this type?"
Preferable to instanceof checks because it correctly handles
union types, intersection types, and all other composite types.
Implements
|
#
|
public
|
isSubTypeOf(Type $otherType): IsSuperTypeOfResult
Answers "is this compound type a subtype of $otherType?" from the compound type's perspective.
Answers "is this compound type a subtype of $otherType?" from the compound type's perspective.
Called by simple types when they encounter a CompoundType argument in their isSuperTypeOf() method.
The compound type decomposes itself and calls $otherType->isSuperTypeOf() for each component.
For example, UnionType(string|int)::isSubTypeOf(MixedType) asks MixedType whether it is
a supertype of string and int separately, then combines with extremeIdentity (all must pass).
Implements
|
#
|
public
|
isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
Answers "is this compound type accepted by $acceptingType?" from the compound type's perspective.
Answers "is this compound type accepted by $acceptingType?" from the compound type's perspective.
Called by simple types when they encounter a CompoundType argument in their accepts() method.
The compound type decomposes itself and calls $acceptingType->accepts() for each component.
For example, UnionType(string|int)::isAcceptedBy(StringType) asks StringType to accept
string and int separately, then combines results with extremeIdentity (all must pass).
Implements
|
#
|
public
|
equals(Type $type): bool
|
#
|
public
|
generalize(GeneralizePrecision $precision): Type
Removes constant value information. E.g. 'foo' -> string, 1 -> int.
Used when types become too complex to track precisely (e.g. loop iterations).
Removes constant value information. E.g. 'foo' -> string, 1 -> int.
Used when types become too complex to track precisely (e.g. loop iterations).
Implements
|
#
|
public
|
isSmallerThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
#
|
public
|
isSmallerThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
|
#
|
public
|
isGreaterThan(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
Compares this compound type against $otherType using greater-than semantics.
Compares this compound type against $otherType using greater-than semantics.
Used for comparison operators (>). Each compound type decomposes the comparison
across its members (e.g., IntegerRangeType checks whether all values in the range
are greater than the other type).
Implements
|
#
|
public
|
isGreaterThanOrEqual(Type $otherType, PhpVersion $phpVersion): TrinaryLogic
Compares this compound type against $otherType using greater-than-or-equal semantics.
Compares this compound type against $otherType using greater-than-or-equal semantics.
Used for comparison operators (>=). Same decomposition strategy as isGreaterThan().
Implements
|
#
|
public
|
getSmallerType(PhpVersion $phpVersion): Type
Type narrowing methods for comparison operators.
For example, for ConstantIntegerType(5), getSmallerType() returns int<min, 4>.
Type narrowing methods for comparison operators.
For example, for ConstantIntegerType(5), getSmallerType() returns int<min, 4>.
Implements
|
#
|
public
|
getSmallerOrEqualType(PhpVersion $phpVersion): Type
|
#
|
public
|
getGreaterType(PhpVersion $phpVersion): Type
|
#
|
public
|
getGreaterOrEqualType(PhpVersion $phpVersion): Type
|
#
|
public
|
toFloat(): Type
An int converts to the float closest to it, which keeps the order of the ints.
An int converts to the float closest to it, which keeps the order of the ints.
Overrides
Implements
|
#
|
public
|
toBoolean(): BooleanType
|
#
|
public
|
toAbsoluteNumber(): Type
|
#
|
public
|
toBitwiseNotType(): Type
Models the bitwise-not (~$x) operator. Returns ErrorType for types where ~ is undefined.
Models the bitwise-not (~$x) operator. Returns ErrorType for types where ~ is undefined.
Overrides
Implements
|
#
|
public
|
toString(): Type
Models the (string) cast.
Models the (string) cast.
Overrides
Implements
|
#
|
public
|
tryUnion(Type $otherType): ?Type
Return the union with another type, but only if it can be expressed in a simpler way than using UnionType
Return the union with another type, but only if it can be expressed in a simpler way than using UnionType
|
#
|
public
|
tryIntersect(Type $otherType): ?Type
Return the intersection with another type, but only if it can be expressed in a simpler way than using
IntersectionType
Return the intersection with another type, but only if it can be expressed in a simpler way than using
IntersectionType
|
#
|
public
|
tryRemove(Type $typeToRemove): ?Type
Return the different with another type, or null if it cannot be represented.
Return the different with another type, or null if it cannot be represented.
Overrides
Implements
|
#
|
public
|
getFiniteTypes(): list<ConstantIntegerType>
Returns a list of finite values this type can take.
Returns a list of finite values this type can take.
Examples:
- for bool: [true, false]
- for int<0, 3>: [0, 1, 2, 3]
- for enums: list of enum cases
- for scalars: the scalar itself
For infinite types it returns an empty array.
Overrides
Implements
|
#
|
public
|
toPhpDocNode(): TypeNode
|
#
|
public
|
looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
|
#
|
public
|
toValueSet(): ValueSet
The values this type holds, by the kinds of values PHP's operators tell apart.
A union of types is the union of their sets, an intersection their intersection.
The values this type holds, by the kinds of values PHP's operators tell apart.
A union of types is the union of their sets, an intersection their intersection.
Overrides
Implements
|
#
|