Search by

larasell-dev / phpstan-rules

Haberkamp

PHPStan rules shared by the Larasell packages

Package info

github.com/Larasell-dev/phpstan-rules

Language:JavaScript

Type:phpstan-extension

pkg:composer/larasell-dev/phpstan-rules

Statistics

Installs: 119

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-10-31 04:28 UTC

This package is auto-updated.

Last update: 2026-10-31 04:31:09 UTC


README

PHPStan rules shared by the Larasell packages, so a mistake one package made is caught in all of them.

Installation

composer require --dev larasell-dev/phpstan-rules

Then include the rules in phpstan.neon:

includes:
    - vendor/larasell-dev/phpstan-rules/extension.neon

With phpstan/extension-installer, skip the include: the rules are registered automatically.

Rules

Mutable Carbon parameter types

Apps can switch Laravel's dates to Carbon\CarbonImmutable with Date::use(CarbonImmutable::class). CarbonImmutable extends neither Illuminate\Support\Carbon nor Carbon\Carbon, so a parameter typed with one of those throws a TypeError as soon as such an app passes it a date, for example a table column's map() callback. Type-hint Carbon\CarbonInterface instead:

// Reported
TextColumn::make('created_at')->map(fn (?Carbon $createdAt) => $createdAt?->diffForHumans());

// Fine
TextColumn::make('created_at')->map(fn (?CarbonInterface $createdAt) => $createdAt?->diffForHumans());

Only parameter types are reported. Returning, creating or calling these classes, e.g. Carbon::today(), is fine.

The rules are configured for spaze/phpstan-disallowed-calls in rules.neon.

Development

composer test       # Pest: runs PHPStan with the rules on tests/Fixtures
composer lint       # Pint
npm run commitlint  # Commitlint on the last commit

Each fixture marks the lines a rule must report with a // forbidden comment; every other line must stay clean.

Changes that make PHPStan report more get an upgrade note in breaking-changes/ and a ! in the pull request title, e.g. feat!: ...; see breaking-changes/AGENT.md. CI checks that both go together. release-please opens the release pull requests.