Search by

hirasso / phpstan-illuminate-collections

hirasso

PHPStan narrowing for filter()/reject()/where() on illuminate/collections, without Larastan

Package info

github.com/hirasso/phpstan-illuminate-collections

Type:phpstan-extension

pkg:composer/hirasso/phpstan-illuminate-collections

Fund package maintenance!

hirasso

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-25 08:55 UTC

This package is auto-updated.

Last update: 2026-11-25 08:57:05 UTC


README

PHPStan type narrowing for filter(), reject(), where() and values()->all() on illuminate/collections, for projects that use collections without Laravel (e.g. WordPress).

The filter/reject/where part is ported from Larastan (CollectionFilterRejectDynamicReturnTypeExtension), which can't be installed without large parts of the Laravel framework. If you use Laravel, use Larastan instead.

/** @var Collection<int, ?Post> $posts */
$posts->filter();                          // Collection<int, Post>
$posts->filter(fn ($p) => $p !== null);    // Collection<int, Post>
$posts->reject();                          // Collection<int, null>
$posts->filter()->values()->all();         // list<Post> (instead of array<int, Post>)

values()->all() only returns a list when chained directly, not via a variable holding the values() result.

Installation

composer require --dev hirasso/phpstan-illuminate-collections

With phpstan/extension-installer you're done. Otherwise, add this to your phpstan.neon:

includes:
    - vendor/hirasso/phpstan-illuminate-collections/extension.neon

Development

composer test
composer analyse