esfahanahan / phpstan-rules
Custom PHPStan rules and extensions for EsfahanAhan.
Package info
github.com/esfahanahan/phpstan-rules
Type:phpstan-extension
pkg:composer/esfahanahan/phpstan-rules
Requires
- php: >=8.1
- phpstan/phpstan: >=2.0
Requires (Dev)
- laravel/pint: >=1.0
- phpunit/phpunit: >=9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-14 09:08:01 UTC
README
Written by Hossein Hosni.
Usage docs: https://esfahanahan.github.io/phpstan-rules
Requirements
- PHP 8.1 or higher
- PHPStan 2.0 or higher
phpstan/extension-installer(recommended)
The nested eager-load rule inspects Eloquent with() call sites. The package does not depend on illuminate/*.
Installation
composer require --dev esfahanahan/phpstan-rules
The dev keyword in composer.json makes Composer offer to install this package into require-dev when composer require is run without --dev.
With phpstan/extension-installer, that is enough. The installer loads extension.neon.
Allow the plugin once:
{
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
Without the installer, include the extension yourself:
includes: - vendor/esfahanahan/phpstan-rules/extension.neon
extension.neon is the file to export. This package will hold rules and other PHPStan extensions (type, reflection, and similar). rules.neon only fits a package that is a ruleset and nothing else.
Rules
Nested eager-load with() must not drop a parent callback
Identifier: esfahanahan.nestedEagerLoadOverwritesConstraint
A later with() for a child relation replaces the parent callback registered by an earlier with().
$query->with([ 'variations' => function (Relation $query): void { $query->where('table_show', true); }, ])->with([ 'variations.attributeItems' => function (Relation $query): void { $query->where('is_show', true); }, ]);
where('table_show', true) is gone. Pass both relations in one with() array. The usage doc shows the safe forms, including when a child callback calls a model scope.
Laravel Boost
The package ships a skill at resources/boost/skills/eloquent-nested-eager-loads. Boost discovers that directory on a direct dependency. Add esfahanahan/phpstan-rules to boost.json packages, keep eloquent-nested-eager-loads in skills, then run Boost's update.
Credit
Written by Hossein Hosni.
Development
composer install
composer test
composer phpstan
composer format