PHPackages                             nxu/typed-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nxu/typed-collection

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

nxu/typed-collection
====================

Laravel collections with strict type support.

v2(4y ago)412.3k1[2 issues](https://github.com/nxu/typed-collection/issues)[1 PRs](https://github.com/nxu/typed-collection/pulls)MITPHPPHP &gt;=8.0.2

Since Feb 18Pushed 2y agoCompare

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

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

This package is abandoned
=========================

[](#this-package-is-abandoned)

Honestly - just use PHPStan at this point.

---

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://stand-with-ukraine.pp.ua)

[![Packagist](https://camo.githubusercontent.com/29a3bfd87f067992c817920969b8f11bd96af250d52cfac6cb158cca4e4186f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e78752f74797065642d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nXu/typed-collection)[![StyleCI](https://camo.githubusercontent.com/68d42d01f9f9421e9d9b3419dc1f1a7f7937bdb19abf77a9b12330b71e52d90b/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132313433393436342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/121439464)

Typed Collections
=================

[](#typed-collections)

While PHP 7 brings nice features for using types as intended, there are many things still missing. One thing I really miss is the use of generics, or simply the ability to type hint an array of elements with specific types. The aim of this package is to provide an alternative way to type-hinted arrays.

How to use?
-----------

[](#how-to-use)

This package is build upon Laravel's Collection and requires illuminate/support. Therefore, while not strictly tied to Laravel, it's intended to be used with the Laravel 5 framework.

It works by creating collection classes for each type and specifying the types of the elements. This will be enforced, and you can be sure the collection only contains elements with the specified type.

### Installation

[](#installation)

Use `composer` to install the package.

```
composer require nxu/typed-collection
```

Not using composer? Too bad.

### Built-in collections

[](#built-in-collections)

The package provides built in collections for all scalar types of PHP (other than `null` of course):

- `ArrayCollection`
- `BooleanCollection`
- `CallableCollection`
- `FloatCollection`
- `IntegerCollection`
- `ResourceCollection`
- `StringCollection`

Also, there is a `DateTimeInterfaceCollection` to be used.

### Custom collection classes

[](#custom-collection-classes)

For any other type, create a class and extend `TypedCollection`. Then simply set the `protected $objectType` property to the FQN of the type you wish to use:

```
protected $objectType = \DateTime::class;
```

That's all, adding any other types will throw an `InvalidTypeException`.

### Even more customization

[](#even-more-customization)

If you wish to customize the collection even more, you can override the `isTypeValid($value): bool` method and add any validation rule.

### Helpers

[](#helpers)

Similarly to Laravel's `collect()` method, this package provides easy to use helper methods:

- `collect_array()`
- `collect_bool()`
- ...

License
-------

[](#license)

This package is open source software licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Every ~219 days

Recently: every ~343 days

Total

8

Last Release

1477d ago

PHP version history (2 changes)v1.0PHP &gt;=7.1

v2PHP &gt;=8.0.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc6f0130fcbd6ba9688046d9f89ca9f72674c6ef4b24108c7f8a7482ce926484?d=identicon)[nxu](/maintainers/nxu)

---

Top Contributors

[![nxu](https://avatars.githubusercontent.com/u/6393515?v=4)](https://github.com/nxu "nxu (34 commits)")

---

Tags

arraycollectionphptype-hinttype-hints

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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