定制 odinns/coding-style 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 odinns/coding-style 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 195
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 36
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25