PHPackages                             soyhuce/empty-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. soyhuce/empty-collection

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

soyhuce/empty-collection
========================

Empty Laravel collections correctly understood by PHPStan

0.1.0(4y ago)111MITPHPPHP ^8.0

Since Mar 2Pushed 4y ago3 watchersCompare

[ Source](https://github.com/Soyhuce/empty-collection)[ Packagist](https://packagist.org/packages/soyhuce/empty-collection)[ RSS](/packages/soyhuce-empty-collection/feed)WikiDiscussions main Synced 1w ago

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

[![Soyhuce](https://camo.githubusercontent.com/39bc99e51c3d4c3968c1a94c5e2d9313567a02bfec25fd4026fd59180ad40507/68747470733a2f2f736f79687563652e66722f77702d636f6e74656e742f75706c6f6164732f323032302f30362f6c6f676f2d736f79687563652d6461726b2d312e706e67 "Soyhuce")](https://camo.githubusercontent.com/39bc99e51c3d4c3968c1a94c5e2d9313567a02bfec25fd4026fd59180ad40507/68747470733a2f2f736f79687563652e66722f77702d636f6e74656e742f75706c6f6164732f323032302f30362f6c6f676f2d736f79687563652d6461726b2d312e706e67)

Empty Laravel collections correctly understood by PHPStan
=========================================================

[](#empty-laravel-collections-correctly-understood-by-phpstan)

[![Latest Version on Packagist](https://camo.githubusercontent.com/733b364a7c1cbde7452412ad30626a27882d5bf2c49204c814d9b1d6d78475a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f79687563652f656d7074792d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soyhuce/empty-collection)[![GitHub Workflow Status](https://camo.githubusercontent.com/4a30bbf625977a2dc06155d0c9a52429720f91985a903fba76b470910008542e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f736f79687563652f656d7074792d636f6c6c656374696f6e2f74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/4a30bbf625977a2dc06155d0c9a52429720f91985a903fba76b470910008542e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f736f79687563652f656d7074792d636f6c6c656374696f6e2f74657374733f6c6162656c3d7465737473)[![Total Downloads](https://camo.githubusercontent.com/777382784f481c36ffef9bc285462593f53bd5e29c85e7ba5acd789a4827c708/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f79687563652f656d7074792d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soyhuce/empty-collection)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require soyhuce/empty-collection
```

Add the provided PHPStan extension in your PHPStan configuration:

```
includes:
  - ./vendor/soyhuce/empty-collection/extension.neon
```

This package does not require `phpstan/phpstan` to be installed in order to keep it in your dev dependencies. Be sure to use version `1.4.6` or higher.

Usage
-----

[](#usage)

Have you ever had some issue with incorrectly typed empty collections in Laravel ? Have you ever seen these PHPStan errors ?

```
Property App\Service\MyService::$items (Illuminate\Support\Collection) does not accept Illuminate\Support\Collection.
Unable to resolve the template type TKey in call to function collect
Unable to resolve the template type TValue in call to function collect
```

We get you covered !

This package provides an easy way to initialise empty collections, correctly typed for PHPStan.

Let's take an example:

```
class MyService {

    /**
     * @var \Illuminate\Support\Collection
     */
    private Collection $items;

    public function __construct()
    {
-        $this->items = collect();
+        $this->items = empty_collection('int', Item::class);
    }
}
```

This way, PHPStan won't complain about the type of the collection.

### Available functions

[](#available-functions)

#### `empty_collection(string $keyType, string $valueType) : \Illuminate\Support\Collection`

[](#empty_collectionstring-keytype-string-valuetype--illuminatesupportcollection)

`$keyType` must be `'int'` or `'string'`. `$valueType` must be some type PHPStan will understand.

Exemples:

```
empty_collection('int', 'int'); // Illuminate\Support\Collection
empty_collection('int', 'string'); // Illuminate\Support\Collection
empty_collection('string', 'array'); // Illuminate\Support\Collection
empty_collection('string', Item::class); // Illuminate\Support\Collection
```

#### `empty_eloquent_collection(string $keyType, string $valueType) : \Illuminate\Database\Eloquent\Collection`

[](#empty_eloquent_collectionstring-keytype-string-valuetype--illuminatedatabaseeloquentcollection)

`$keyType` must be `'int'` or `'string'`. `$valueType` must be a class name.

Exemples:

```
empty_eloquent_collection('int', User::class); // Illuminate\Database\Eloquent\Collection
empty_eloquent_collection('string', User::class); // Illuminate\Database\Eloquent\Collection
```

Testing
-------

[](#testing)

Testing is done via PHPStan and can be run with

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1536d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/206cfbf866a463f7e7d1e86946d59b82f4191b9c89f9981fb03eeb264d77af79?d=identicon)[SoyHuCe](/maintainers/SoyHuCe)

---

Top Contributors

[![bastien-phi](https://avatars.githubusercontent.com/u/10199039?v=4)](https://github.com/bastien-phi "bastien-phi (11 commits)")

---

Tags

PHPStanlaravelcollection

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/soyhuce-empty-collection/health.svg)](https://phpackages.com/packages/soyhuce-empty-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)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[glhd/special

1929.4k](/packages/glhd-special)[bjuppa/laravel-blog

Add blog functionality to your Laravel project

483.3k2](/packages/bjuppa-laravel-blog)

PHPackages © 2026

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