Shared Rector and PHPStan defaults for Laravel projects.
This package gives Laravel apps a small, boring way to share static-analysis and automated-refactoring rules. The package owns the defaults. Each application owns its paths, baselines, ignore rules, and local skips.
That split matters. Shared config should describe current taste. Local config should describe local history.
- PHP
^8.3 - Composer 2
- Rector 2
- PHPStan 2
- Laravel 11, 12, or 13 through Larastan support
Install the published package as a development dependency:
composer require --dev odinns/coding-styleThe package installs Rector, PHPStan, Larastan, and the supported PHPStan extensions it configures.
For local development, install this checkout into another Laravel project as a Composer path repository:
composer config repositories.odinns-coding-style path ~/Projects/odinns/coding-style
composer require --dev 'odinns/coding-style:*@dev'Then copy the starter config files:
cp vendor/odinns/coding-style/stubs/rector.php.stub rector.php
cp vendor/odinns/coding-style/stubs/phpstan.neon.stub phpstan.neonIf the consuming project already has rector.php or phpstan.neon, merge the package calls into the existing files instead of overwriting them.
Create a rector.php file in the consuming project:
<?php
declare(strict_types=1);
use Odinns\CodingStyle\OdinnsRectorConfig;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
OdinnsRectorConfig::setup($rectorConfig);
$rectorConfig->paths([
__DIR__ . '/app',
__DIR__ . '/bootstrap',
__DIR__ . '/config',
__DIR__ . '/database',
__DIR__ . '/routes',
__DIR__ . '/tests',
]);
};Then add Composer scripts:
{
"scripts": {
"refactor": "rector process --ansi",
"test:refactor": "rector process --dry-run --ansi"
}
}Run Rector in check mode:
composer test:refactorApply changes:
composer refactorKeep skips in the consuming project:
return static function (RectorConfig $rectorConfig): void {
OdinnsRectorConfig::setup($rectorConfig);
$rectorConfig->paths([
__DIR__ . '/app',
__DIR__ . '/tests',
]);
$rectorConfig->skip([
__DIR__ . '/app/Legacy',
SomeProjectSpecificRector::class,
]);
};Do not upstream local skip lists into this package. A skip caused by one app's history is not a coding standard.
Create a phpstan.neon file in the consuming project:
includes:
- vendor/odinns/coding-style/config/larastan.neon
parameters:
paths:
- app
- bootstrap
- config
- database
- routes
- tests
level: 5Then add Composer scripts:
{
"scripts": {
"test:types": "phpstan analyse --memory-limit=2G",
"test:types:baseline": "phpstan analyse --generate-baseline --memory-limit=2G"
}
}Run PHPStan:
composer test:typesBaselines belong to the consuming project:
includes:
- vendor/odinns/coding-style/config/larastan.neon
- phpstan-baseline.neon
parameters:
paths:
- app
- tests
level: 5Generate a baseline:
composer test:types:baselineBaselines are debt registers. Keep them local and shrink them when the code changes nearby.
Project-specific ignores also stay local:
includes:
- vendor/odinns/coding-style/config/larastan.neon
parameters:
paths:
- app
- tests
level: 5
ignoreErrors:
-
identifier: some.local.identifier
path: app/Legacy/OldThing.phpIf an ignore only makes sense in one app, it does not belong in this package.
The shared Rector setup enables conservative automated improvements:
- dead-code cleanup
- code-quality cleanup
- type declaration improvements
- safe privatization
- early returns
- import cleanup
- required
declare(strict_types=1);declarations - PHP 8.3 set support
- Laravel relation generic return types
- Laravel model casts method migration
- Laravel validation rule array conversion
The package automatically uses the consuming project's phpstan.neon when it exists, falling back to phpstan.neon.dist. It also loads Larastan's bootstrap file when the consuming project has one installed.
The base PHPStan config enables:
- deprecation rules
- Mockery support
- stricter return type checks
- missing override attribute checks
- safer array-offset reporting
- less overconfident PHPDoc treatment
The Larastan config adds:
- Larastan
- model property checks
- Octane compatibility checks
Copy-ready stubs are included:
vendor/odinns/coding-style/stubs/rector.php.stub
vendor/odinns/coding-style/stubs/phpstan.neon.stub
They are deliberately plain files. No generator command. No plugin. No theatrical machinery.
Use normal Composer updates:
composer update odinns/coding-style --with-dependenciesAfter updating, run:
composer test:refactor
composer test:typesIf Rector proposes a large change set, review it as a normal refactor. Automated does not mean harmless. It means repeatable.
- Shared defaults should be stable and boring.
- Local paths stay local.
- Local skips stay local.
- Local baselines stay local.
- Rules should remove noise, not rewrite taste every Tuesday.
- The package should be easy to delete from a project if it stops earning its keep.
- It does not publish Laravel config.
- It does not register a service provider.
- It does not add migrations, routes, views, or commands.
- It does not own application-specific baselines.
- It does not own application-specific Rector skips.
- It does not try to format code. Use a formatter separately.
The package test suite uses Pest.
Add tests under tests/Unit:
<?php
declare(strict_types=1);
it('describes behavior clearly', function (): void {
expect(true)->toBeTrue();
});Run the suite:
composer testInstall dependencies:
composer installRun all checks:
composer test:allRun checks separately:
composer validate --strict
composer test:types
composer test:refactor
composer testKeep changes small and explain the behavior change. Add shared rules only when they are broadly useful across Laravel projects.
Do not add one application's skip list, baseline, or legacy exception to this package. That path leads to a swamp with invoices.
If you discover a security issue, report it privately to the maintainer instead of opening a public issue.
The MIT License. See LICENSE.