sustainabil-it/phpstan-higher-order-collections

Higher Order Collection Support for PHPStan

dev-main 2023-02-27 10:39 UTC

This package is auto-updated.

Last update: 2024-04-27 13:15:31 UTC


README

This plugin adds PHPStan support to Higher Order Messaging on the Collection concept popularized by Laravel.

This extension provides following features:

  • Illuminate\Support\Collection knows the type(s) of its contents using PHPStan Generics, which ensures that methods called on the Proxy objects are actually valid, and have their return types correctly inferred.

Installation

To use this extension, require it in Composer:

composer require --dev sustainabil-it/phpstan-higher-order-collections

This plugin exposes a few configuration options if you happen to have special needs, like your own Collection implementation:

parameters:
    higherOrderCollection:
        - collectionClass: Illuminate\Support\Enumerable
        - proxyClass: Illuminate\Support\HigherOrderCollectionProxy
        - keyTemplate: TKey
        - typeTemplate: TValue
        - proxyTemplate: TReturn
        - proxyMethods:
            - map
            - filter

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/sustainabil-it/phpstan-higher-order-collections/extension.neon