New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

hirasso/phpstan-illuminate-collections

PHPStan narrowing for filter()/reject()/where() on illuminate/collections, without Larastan
5 1
Install
composer require hirasso/phpstan-illuminate-collections
Latest Version:v1.0.0
PHP:^8.2
Laravel:11 · 12 · 13
License:MIT
Last Updated:Nov 25, 2026
Links: GitHub  ·  Packagist
Maintainer: hirasso

phpstan-illuminate-collections

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

Related Packages

tomasvotruba/bladestan

PHPStan rule for static analysis of Blade templates

1,117,809 373
calebdw/phpstan-laravel

A PHPStan extension for analysis of Laravel applications and packages.

31,283 38
shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatica...

8,070,745 539
calebdw/larastan-livewire

A Larastan / PHPStan extension for Livewire.

1,239,100 66

Version History

Version Released PHP Laravel License
v1.0.0 ^8.2 ^11 || ^12 || ^13 MIT