| Methods |
public
|
__construct(Type $keyType, Type $itemType)
|
#
|
public
|
getKeyType(): Type
|
#
|
public
|
getItemType(): Type
|
#
|
protected
|
withTypes(Type $keyType, Type $itemType): self
Build a same-kind array with new key/item types. Subclasses
(e.g. TemplateArrayType ) override this to preserve their
extra metadata across array-mutating operations such as offset
writes and unsets.
Build a same-kind array with new key/item types. Subclasses
(e.g. TemplateArrayType ) override this to preserve their
extra metadata across array-mutating operations such as offset
writes and unsets.
Overridden by
|
#
|
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. It's also used to model array after sort / rsort / usort calls.
Models shuffle() effect on the array. Result is always a list. It's also used to model array after sort / rsort / usort calls.
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
|
makeListMaybe(): Type
Downgrades the list-ness of the array from Yes to Maybe (e.g. for
asort/uksort/etc. which preserve keys but break list ordering).
Other shape information (keys, values, accessories like NonEmpty) is
preserved.
Downgrades the list-ness of the array from Yes to Maybe (e.g. for
asort/uksort/etc. which preserve keys but break list ordering).
Other shape information (keys, values, accessories like NonEmpty) is
preserved.
Implements
|
#
|
public
|
mapValueType(callable $cb): Type
Models "same keys, every value transformed" (e.g. array_walk,
array_map($cb, $a), preg_replace* over an array subject). Keys
and accessories like list-ness / non-emptiness are preserved.
Models "same keys, every value transformed" (e.g. array_walk,
array_map($cb, $a), preg_replace* over an array subject). Keys
and accessories like list-ness / non-emptiness are preserved.
Implements
|
#
|
public
|
mapKeyType(callable $cb): Type
Replaces the iterable key type via $cb($currentKeyType). For
ArrayType rewrites the key type wholesale; for ConstantArrayType
the explicit keys (which are already precise constants) are preserved
— pass-through, matching the prior TypeTraverser-based callers.
Used to widen / narrow the key type after a foreach narrowed $key
via is_int($key) / is_string($key) checks.
Replaces the iterable key type via $cb($currentKeyType). For
ArrayType rewrites the key type wholesale; for ConstantArrayType
the explicit keys (which are already precise constants) are preserved
— pass-through, matching the prior TypeTraverser-based callers.
Used to widen / narrow the key type after a foreach narrowed $key
via is_int($key) / is_string($key) checks.
Implements
|
#
|
public
|
makeAllArrayKeysOptional(): Type
Marks every explicit key in a ConstantArrayType as optional (the
shape can have any subset of the original keys). For non-CAT arrays
this is a no-op — they already model arbitrary subsets. Used by
preg_replace* over array subjects, where the callback can drop
entries.
Marks every explicit key in a ConstantArrayType as optional (the
shape can have any subset of the original keys). For non-CAT arrays
this is a no-op — they already model arbitrary subsets. Used by
preg_replace* over array subjects, where the callback can drop
entries.
Implements
|
#
|
public
|
changeKeyCaseArray(?int $case): Type
Models array_change_key_case($a, $case). String keys are case-folded
(constant ones to a specific value, general ones via accessories);
non-string keys, values, accessories and list-ness are preserved.
$case matches PHP's CASE_LOWER / CASE_UPPER; null means the
case is non-constant and the result is the union of both folds.
Models array_change_key_case($a, $case). String keys are case-folded
(constant ones to a specific value, general ones via accessories);
non-string keys, values, accessories and list-ness are preserved.
$case matches PHP's CASE_LOWER / CASE_UPPER; null means the
case is non-constant and the result is the union of both folds.
Implements
|
#
|
public
|
filterArrayRemovingFalsey(): Type
Models array_filter($a) (no callback): drops entries whose value is
definitely falsey, marks possibly-falsey entries optional, keeps
definitely-truthy entries unchanged. Keys are preserved; list-ness
is downgraded since gaps may appear.
Models array_filter($a) (no callback): drops entries whose value is
definitely falsey, marks possibly-falsey entries optional, keeps
definitely-truthy entries unchanged. Keys are preserved; list-ness
is downgraded since gaps may appear.
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
|
#
|