odinns/coding-style
Composer 安装命令:
composer require odinns/coding-style
包简介
Shared Rector and PHPStan defaults for Laravel projects.
README 文档
README
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.
Requirements
- PHP
^8.3 - Composer 2
- Rector 2
- PHPStan 2
- Laravel 11, 12, or 13 through Larastan support
Installation
Install the published package as a development dependency:
composer require --dev odinns/coding-style
The package installs Rector, PHPStan, Larastan, and the supported PHPStan extensions it configures.
Local Path Install
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.neon
If the consuming project already has rector.php or phpstan.neon, merge the package calls into the existing files instead of overwriting them.
Rector
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:refactor
Apply changes:
composer refactor
Local Rector skips
Keep 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.
PHPStan and Larastan
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: 5
Then 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:types
Baselines
Baselines belong to the consuming project:
includes: - vendor/odinns/coding-style/config/larastan.neon - phpstan-baseline.neon parameters: paths: - app - tests level: 5
Generate a baseline:
composer test:types:baseline
Baselines are debt registers. Keep them local and shrink them when the code changes nearby.
Local ignores
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.php
If an ignore only makes sense in one app, it does not belong in this package.
Included Defaults
Rector
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.
PHPStan
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
Stubs
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.
Update Strategy
Use normal Composer updates:
composer update odinns/coding-style --with-dependencies
After updating, run:
composer test:refactor composer test:types
If Rector proposes a large change set, review it as a normal refactor. Automated does not mean harmless. It means repeatable.
Design Principles
- 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.
What This Package Does Not Do
- 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.
Testing With Pest
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 test
Developing This Package
Install dependencies:
composer install
Run all checks:
composer test:all
Run checks separately:
composer validate --strict
composer test:types
composer test:refactor
composer test
Contributing
Keep 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.
Security
If you discover a security issue, report it privately to the maintainer instead of opening a public issue.
License
The MIT License. See LICENSE.
odinns/coding-style 适用场景与选型建议
odinns/coding-style 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 195 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「laravel」 「static-analysis」 「PHPStan」 「larastan」 「code-quality」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 odinns/coding-style 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 odinns/coding-style 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 odinns/coding-style 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Validates PHPDoc @param and @return tags against method signatures
Rules for the bdd-analyser CLI tool
A PHP security linter to detect insecure functions like var_dump, print_r, and other dangerous functions in your codebase
finding mismatch type assignment in function/method scope with psalm
Laravel package that scans applications (including Livewire) for security vulnerabilities, reports issues with severity levels, and provides remediation guidance and optional automated fixes.
Static analysis for Eloquent column references — finds invalid database column names in your Laravel code before they hit production.
统计信息
- 总下载量: 195
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-25