PHPackages                             jakubgiminski/collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. jakubgiminski/collection

ActiveLibrary

jakubgiminski/collection
========================

2.0.0(5y ago)1460PHP

Since Jul 10Pushed 5y agoCompare

[ Source](https://github.com/jakubgiminski/collection)[ Packagist](https://packagist.org/packages/jakubgiminski/collection)[ RSS](/packages/jakubgiminski-collection/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Collection
==========

[](#collection)

A library that lets you create collections of typed and/or unique elements. In order to use it, simply have your collection class extend the abstract `Collection` and set it up in the constructor.

### Installation

[](#installation)

Minimum required php version is `7.4`

```
composer require jakubgiminski/collection

```

### Examples

[](#examples)

Here's an example of a `UserCollection` - a collection of elements where each one must be an instance of `User`. Also, every `User` in the collection must have a unique id.

```
class UserCollection extends Collection
{
    public function __construct(array $users = [])
    {
        parent::__construct(
            $users,
            // Set up typing - every element must be an instance of User
            Type::object(User::class),
            // Set up a unique index - user id
            new UniqueIndex(function (User $user) {
                return $user->getId();
            })
        );
    }
}
```

In this example we have an array collection of addresses, where the unique index is the entire address (all the fields concatenated).

```
class AddressCollection extends Collection
{
    public function __construct(array $addresses = [])
    {
        parent::__construct(
            $addresses,
            // Set up typing - every element must be an array
            Type::array(),
            // Set up a unique index - all the fields
            new UniqueIndex(function (array $address) {
                return $address['postCode'] . $address['street'] . $address['homeNumber'];
            })
        );
    }
}
```

`Collection` also supports primitive types such as `int` or `string`. Head to the [tests](https://github.com/jakubgiminski/collection/tree/master/tests) section to examine more use cases.

### Documentation

[](#documentation)

Naturally, `Collection` does what any collection would do - you can count it, iterate over it, add and remove elements. If the collection has a unique index set, you can also get elements from the collection by that index.

```
Collection::add($element): self;
Collection::addMany(self $collection): void;
Collection::filter(callable $filter): self;
Collection::remove($element): self;
Collection::get($uniqueIndex): self;
Collection::count(): int;
Collection::getElements(): array;
Collection::isTyped(): bool;
Collection::hasUniqueIndex(): bool;
Collection::rewind();
Collection::current();
Collection::key();
Collection::next();
Collection::valid();
Collection::isEmpty(): bool;
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2129d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92a0afe347848290e705a28ecd2b6bca4c5029ef8cbf53d000f4f9fb2e9c600e?d=identicon)[jakubgiminski](/maintainers/jakubgiminski)

---

Top Contributors

[![jakubgiminski](https://avatars.githubusercontent.com/u/1197853?v=4)](https://github.com/jakubgiminski "jakubgiminski (50 commits)")[![rowBawTick](https://avatars.githubusercontent.com/u/45603847?v=4)](https://github.com/rowBawTick "rowBawTick (2 commits)")

---

Tags

collectionsphp74typed

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jakubgiminski-collection/health.svg)

```
[![Health](https://phpackages.com/badges/jakubgiminski-collection/health.svg)](https://phpackages.com/packages/jakubgiminski-collection)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
