class CollectionHelper

Constants

private FRAMEWORK_COLLECTIONS

The framework collections, whose own method implementations the extensions and rules rely on.

Methods

__construct(ReflectionProvider $reflectionProvider, DeclarationDependencyTracker $declarationDependencyTracker, AttributeClassNameResolver $attributeClassNames)

Create a new collection helper instance.

static bool
usesFrameworkMethods(ClassReflection $classReflection, array $methods)

Determine whether the class runs a framework collection's own implementation of each method, which a subclass may override.

static bool
isFrameworkQueryMethod(MethodReflection $methodReflection)

Determine whether a framework builder or relation implements the method, so the model's newCollection() creates the collections it returns. A custom builder's or relation's override keeps its declaration.

GenericObjectType|null
determineGenericCollectionTypeFromType(Type $type)

Get the collection type that collect() makes from a scalar, null or an empty array.

bool
usesFrameworkNewCollection(ClassReflection $modelReflection)

Determine whether the model creates its collections with HasCollection::newCollection(), which uses the CollectedBy attribute or the static $collectionClass.

Type
determineCollectionClass(string $modelClassName, Type|null $modelType = null, Type|null $keyType = null)

Get the collection type of the model, with the model and key types filled in.

Type
replaceCollectionsInType(Type $type)

Replace each Eloquent collection in the type with its model's collection type.

Details

at line 65
__construct(ReflectionProvider $reflectionProvider, DeclarationDependencyTracker $declarationDependencyTracker, AttributeClassNameResolver $attributeClassNames)

Create a new collection helper instance.

Parameters

ReflectionProvider $reflectionProvider
DeclarationDependencyTracker $declarationDependencyTracker
AttributeClassNameResolver $attributeClassNames

at line 78
static bool usesFrameworkMethods(ClassReflection $classReflection, array $methods)

Determine whether the class runs a framework collection's own implementation of each method, which a subclass may override.

Parameters

ClassReflection $classReflection
array $methods

Return Value

bool

at line 94
static bool isFrameworkQueryMethod(MethodReflection $methodReflection)

Determine whether a framework builder or relation implements the method, so the model's newCollection() creates the collections it returns. A custom builder's or relation's override keeps its declaration.

Parameters

MethodReflection $methodReflection

Return Value

bool

at line 117
GenericObjectType|null determineGenericCollectionTypeFromType(Type $type)

Get the collection type that collect() makes from a scalar, null or an empty array.

collect()'s declared signature already describes objects and other arrays. Upstream also typed objects here, casting Arrayable objects with (array) instead of reading toArray(), and forcing integer keys onto Eloquent collections.

Parameters

Type $type

Return Value

GenericObjectType|null

at line 214
bool usesFrameworkNewCollection(ClassReflection $modelReflection)

Determine whether the model creates its collections with HasCollection::newCollection(), which uses the CollectedBy attribute or the static $collectionClass.

Parameters

ClassReflection $modelReflection

Return Value

bool

at line 223
Type determineCollectionClass(string $modelClassName, Type|null $modelType = null, Type|null $keyType = null)

Get the collection type of the model, with the model and key types filled in.

Parameters

string $modelClassName
Type|null $modelType
Type|null $keyType

Return Value

Type

at line 270
Type replaceCollectionsInType(Type $type)

Replace each Eloquent collection in the type with its model's collection type.

Parameters

Type $type

Return Value

Type