PHPackages                             fkupper/psalm-laravel-collections - 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. fkupper/psalm-laravel-collections

AbandonedPsalm-plugin[Utility &amp; Helpers](/categories/utility)

fkupper/psalm-laravel-collections
=================================

Stubs to let Psalm understand Laravel Collections better

v6.0.0(5y ago)95602MITGherkinPHP ^7.2

Since Aug 12Pushed 5y ago2 watchersCompare

[ Source](https://github.com/fkupper/psalm-laravel-collections)[ Packagist](https://packagist.org/packages/fkupper/psalm-laravel-collections)[ RSS](/packages/fkupper-psalm-laravel-collections/feed)WikiDiscussions master Synced yesterday

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

psalm-laravel-collections
=========================

[](#psalm-laravel-collections)

[![Build Status](https://camo.githubusercontent.com/2e0e64b1d7eea613d98dbe8fc0e139f7c48d6a4e69d210b1a9dfb45e39efb2ff/68747470733a2f2f7472617669732d63692e6f72672f666b75707065722f7073616c6d2d6c61726176656c2d636f6c6c656374696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/fkupper/psalm-laravel-collections)[![Total Downloads](https://camo.githubusercontent.com/27de76e2b7cd95c3944e8e9ae7ec31bdbe2175c0513e691dfb136634589f533f/68747470733a2f2f706f7365722e707567782e6f72672f666b75707065722f7073616c6d2d6c61726176656c2d636f6c6c656374696f6e732f646f776e6c6f616473)](//packagist.org/packages/fkupper/psalm-laravel-collections)[![Monthly Downloads](https://camo.githubusercontent.com/d97bb9f381ab1659bba146173384c0982e503985826b1e95aa5f8874ef95b9d2/68747470733a2f2f706f7365722e707567782e6f72672f666b75707065722f7073616c6d2d6c61726176656c2d636f6c6c656374696f6e732f642f6d6f6e74686c79)](//packagist.org/packages/fkupper/psalm-laravel-collections)

A [Laravel](https://github.com/laravel/laravel)'s `\Illuminate\Support\Collection` plugin for [Psalm](https://github.com/vimeo/psalm) (requires Psalm v3) to help you find errors in some cases where you use collections.

Installation:
-------------

[](#installation)

```
$ composer require --dev fkupper/psalm-laravel-collections
$ vendor/bin/psalm-plugin enable fkupper/psalm-laravel-collections
```

Examples
--------

[](#examples)

### Accessing array with wrong key type

[](#accessing-array-with-wrong-key-type)

```
/** @var Collection */
$c = new Collection(['a' => 'A', 'b' => 'B', 'c' => 'C']);
$items = $c->all();
$items[1];
```

### Adding an item of invalid type

[](#adding-an-item-of-invalid-type)

```
/** @var Collection */
$c = new Collection(["a", "b", "c"]);
// items type is deinfed as string, cannot add int
$c->add(1);
```

### Asserting collection item value type

[](#asserting-collection-item-value-type)

```
/**
 * @param Collection
 */
function(Collection $coll): void {
    $exception = $coll->first();
    // psalm will report this typo
    $exception->getMassage();
}

/**
 * @param Collection
 */
function(Collection $coll): int {
    $value = $coll->first();
    // psalm will remind you forgot to cast that $value to int
    return $value + 1;
}
```

### Better assertion of helper methods, like `Collection::filter`

[](#better-assertion-of-helper-methods-like-collectionfilter)

```
/**
 * This function is using wrong types in the filter Closure params.
 * @param Collection
 */
function(Collection $coll): void {
    $filteredValues = $coll->filter(
        // psalm will tell you that the Closure params are wrong
        function (bool $value, float $key): bool {
            return true;
        }
    )
}

/**
 * @param Collection
 */
function(Collection $coll): void {
    $filteredValues = $coll->filter(
        function (int $value, string $key): bool {
            return true;
        }
    )
    // psalm understands that the result of the filter call
    // is a collection of same type as it was before, so the value
    // type is still string, therefore array cannot be added
    $filteredValues->add(['something']);
}
```

Work In Progress
----------------

[](#work-in-progress)

This is a work in progress project, therefore not all Collection methods have had their templates extended, or tested.

Please report any issues you may find, and even beetter, make a pull request with a fix!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

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

2099d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/599fb5c824458d0e5cb099f6b83f0bd158c1c094f5d52821784f437ecf849741?d=identicon)[fernando.kupper](/maintainers/fernando.kupper)

---

Top Contributors

[![fkupper](https://avatars.githubusercontent.com/u/10757561?v=4)](https://github.com/fkupper "fkupper (11 commits)")[![nederdirk](https://avatars.githubusercontent.com/u/778965?v=4)](https://github.com/nederdirk "nederdirk (1 commits)")

---

Tags

collectionsgenericslaravelpsalmpsalm-pluginphppluginlaravelstatic analysiscodeinspectioncollectionextensionlaravel6psalmpsalm-plugin

###  Code Quality

TestsCodeception

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/fkupper-psalm-laravel-collections/health.svg)

```
[![Health](https://phpackages.com/badges/fkupper-psalm-laravel-collections/health.svg)](https://phpackages.com/packages/fkupper-psalm-laravel-collections)
```

###  Alternatives

[weirdan/doctrine-psalm-plugin

Stubs to let Psalm understand Doctrine better

876.9M50](/packages/weirdan-doctrine-psalm-plugin)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[lctrs/psalm-psr-container-plugin

Let Psalm understand better psr11 containers

17648.1k13](/packages/lctrs-psalm-psr-container-plugin)[amirezaeb/heroqr

A Powerful QR Code Management Library For PHP

9510.3k](/packages/amirezaeb-heroqr)[lazerg/laravel-enum-pro

A powerful PHP enum extension with collection support, random selection, and magic static calls

4319.0k](/packages/lazerg-laravel-enum-pro)[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)

PHPackages © 2026

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