| Methods |
public
|
__construct(Type $keyType, Type $itemType)
|
#
|
public
|
getKeyType(): Type
|
#
|
public
|
getItemType(): Type
|
#
|
public
|
getReferencedClasses(): array
Returns all class names referenced anywhere in this type, recursively
(including generic arguments, callable signatures, etc.).
Returns all class names referenced anywhere in this type, recursively
(including generic arguments, callable signatures, etc.).
Implements
|
#
|
public
|
getConstantArrays(): array
Only ConstantArrayType instances (array shapes with known keys).
Only ConstantArrayType instances (array shapes with known keys).
Implements
|
#
|
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?" Preferable to instanceof checks because it correctly handles
union types, intersection types, and all other composite types.
"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
|
equals(Type $type): bool
|
#
|
public
|
describe(VerbosityLevel $level): string
|
#
|
public
|
generalizeValues(): self
|
#
|
public
|
getKeysArrayFiltered(Type $filterValueType, TrinaryLogic $strict): Type
Models array_keys($array, $searchValue, $strict).
Models array_keys($array, $searchValue, $strict).
Implements
|
#
|
public
|
getKeysArray(): Type
Models array_keys($array).
Models array_keys($array).
Implements
|
#
|
public
|
getValuesArray(): Type
Models array_values($array).
Models array_values($array).
Implements
|
#
|
public
|
isIterableAtLeastOnce(): TrinaryLogic
|
#
|
public
|
getArraySize(): Type
Returns the count of elements as a Type (typically IntegerRangeType).
Returns the count of elements as a Type (typically IntegerRangeType).
Implements
|
#
|
public
|
getIterableKeyType(): Type
Works for both arrays and Traversable objects.
Works for both arrays and Traversable objects.
Implements
|
#
|
public
|
getFirstIterableKeyType(): Type
|
#
|
public
|
getLastIterableKeyType(): Type
|
#
|
public
|
getIterableValueType(): Type
|
#
|
public
|
getFirstIterableValueType(): Type
|
#
|
public
|
getLastIterableValueType(): Type
|
#
|
public
|
isConstantArray(): TrinaryLogic
|
#
|
public
|
isList(): TrinaryLogic
A list is an array with sequential integer keys starting from 0 with no gaps.
A list is an array with sequential integer keys starting from 0 with no gaps.
Implements
|
#
|
public
|
isConstantValue(): TrinaryLogic
Is Type of a known constant value? Includes literal strings, integers, floats, true, false, null, and array shapes. Unlike isConstantScalarValue(), this also returns yes for constant array types (array shapes
with known keys and values). Use this when you need to detect any constant value including arrays.
Is Type of a known constant value? Includes literal strings, integers, floats, true, false, null, and array shapes. Unlike isConstantScalarValue(), this also returns yes for constant array types (array shapes
with known keys and values). Use this when you need to detect any constant value including arrays.
Implements
|
#
|
public
|
looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
|
#
|
public
|
hasOffsetValueType(Type $offsetType): TrinaryLogic
|
#
|
public
|
getOffsetValueType(Type $offsetType): Type
|
#
|
public
|
setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type
May add a new key. When $offsetType is null, appends (like $a[] = $value).
May add a new key. When $offsetType is null, appends (like $a[] = $value).
Implements
|
#
|
public
|
setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
Unlike setOffsetValueType(), assumes the key already exists.
Preserves the array shape and list type.
Unlike setOffsetValueType(), assumes the key already exists.
Preserves the array shape and list type.
Implements
|
#
|
public
|
unsetOffset(Type $offsetType): Type
|
#
|
public
|
fillKeysArray(Type $valueType): Type
Models array_fill_keys($keys, $value).
Models array_fill_keys($keys, $value).
Implements
|
#
|
public
|
flipArray(): Type
Models array_flip($array).
Models array_flip($array).
Implements
|
#
|
public
|
intersectKeyArray(Type $otherArraysType): Type
Models array_intersect_key($array, ...$otherArrays).
Models array_intersect_key($array, ...$otherArrays).
Implements
|
#
|
public
|
popArray(): Type
Models array_pop() effect on the array.
Models array_pop() effect on the array.
Implements
|
#
|
public
|
reverseArray(TrinaryLogic $preserveKeys): Type
Models array_reverse($array, $preserveKeys).
Models array_reverse($array, $preserveKeys).
Implements
|
#
|
public
|
searchArray(Type $needleType, ?TrinaryLogic $strict = null): Type
Models array_search($needle, $array, $strict).
Models array_search($needle, $array, $strict).
Implements
|
#
|
public
|
shiftArray(): Type
Models array_shift() effect on the array.
Models array_shift() effect on the array.
Implements
|
#
|
public
|
shuffleArray(): Type
Models shuffle() effect on the array. Result is always a list.
Models shuffle() effect on the array. Result is always a list.
Implements
|
#
|
public
|
sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
Models array_slice($array, $offset, $length, $preserveKeys).
Models array_slice($array, $offset, $length, $preserveKeys).
Implements
|
#
|
public
|
spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type
Models array_splice() effect on the array (the modified array, not the removed portion).
Models array_splice() effect on the array (the modified array, not the removed portion).
Implements
|
#
|
public
|
isCallable(): TrinaryLogic
|
#
|
public
|
getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
|
#
|
public
|
toInteger(): Type
|
#
|
public
|
toFloat(): Type
|
#
|
public
|
inferTemplateTypes(Type $receivedType): TemplateTypeMap
Infers the real types of TemplateTypes found in $this, based on
the received Type. E.g. if $this is array<T> and $receivedType
is array, infers T = int.
Infers the real types of TemplateTypes found in $this, based on
the received Type. E.g. if $this is array<T> and $receivedType
is array, infers T = int.
Implements
|
#
|
public
|
getReferencedTemplateTypes(TemplateTypeVariance $positionVariance): array
Returns the template types referenced by this Type, recursively. The return value is a list of TemplateTypeReferences, who contain the
referenced template type as well as the variance position in which it was
found. For example, calling this on array<Foo<T>,Bar> (with T a template type)
will return one TemplateTypeReference for the type T.
Returns the template types referenced by this Type, recursively. The return value is a list of TemplateTypeReferences, who contain the
referenced template type as well as the variance position in which it was
found. For example, calling this on array<Foo<T>,Bar> (with T a template type)
will return one TemplateTypeReference for the type T.
Parameters
| $positionVariance |
The variance position in
which the receiver type was
found.
|
Implements
|
#
|
public
|
traverse(callable $cb): Type
Returns a new instance with all inner types mapped through $cb.
Returns the same instance if inner types did not change. Not used directly — use TypeTraverser::map() instead.
Returns a new instance with all inner types mapped through $cb.
Returns the same instance if inner types did not change. Not used directly — use TypeTraverser::map() instead.
Implements
|
#
|
public
|
toPhpDocNode(): TypeNode
|
#
|
public
|
traverseSimultaneously(Type $right, callable $cb): Type
Like traverse(), but walks two types simultaneously. Not used directly — use SimultaneousTypeTraverser::map() instead.
Like traverse(), but walks two types simultaneously. Not used directly — use SimultaneousTypeTraverser::map() instead.
Implements
|
#
|
public
|
tryRemove(Type $typeToRemove): ?Type
|
#
|
public
|
getFiniteTypes(): array
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.
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.
Implements
|
#
|
public
|
hasTemplateOrLateResolvableType(): bool
Performance optimization to skip template resolution when no templates are present.
Performance optimization to skip template resolution when no templates are present.
Implements
|
#
|