interaction-design-foundation/coding-standard
Composer 安装命令:
composer require interaction-design-foundation/coding-standard
包简介
IxDF coding standard: PHP_CodeSniffer rules and shared PHP-CS-Fixer configuration.
README 文档
README
An opinionated coding standard for PHP and Laravel projects, built on PER-CS 3. Focuses on:
- High signal-to-noise ratio (concise but informative PHPDoc, e.g. array shapes)
- Strict, explicit code:
strict_types, strict comparisons, final by default, no magic - Harmony with static analysis tools (PHPStan, Psalm, Rector, etc.)
- Auto-fixing over reporting (violations are not only reported but fixed automatically, when possible)
- PHP and Laravel best practices (enforced, not just suggested)
Two tools, two roles, meant to run together:
- PHP-CS-Fixer (primary): fast auto-formatting and modernization rules.
- PHP_CodeSniffer (supplementary): structural and semantic checks PHP-CS-Fixer cannot express (complexity, Laravel conventions, naming).
Tip
This repository is a part of the IxDF toolchain for PHP: Rector ➝ Coding Standard Fixers ➝ PHPStan + Psalm.
1. Installation
composer require --dev interaction-design-foundation/coding-standard
2. Configuration
PHP-CS-Fixer
Primary formatter.
Create .php-cs-fixer.php in your project root:
<?php declare(strict_types=1); use IxDFCodingStandard\PhpCsFixer\Config; // @see https://mlocati.github.io/php-cs-fixer-configurator/ for ruleOverrides options. return Config::create(__DIR__, ruleOverrides: []);
Customisation (optional)
Config::create() ships a sensible default Finder and enables parallel runs, risky rules, and caching.
You can customize it by using your Finder instance and by overriding individual rules:
use PhpCsFixer\Finder; $finder = Finder::create()->in(__DIR__)->name('*.php'); // Override individual rules, your own Finder and use your cache path return Config::create(__DIR__, finder: $finder, ruleOverrides: [ 'final_class' => true, ])->setCacheFile('./.cache/.php-cs-fixer.cache');
Need only the rule array (e.g. to compose your own config)?
$rules = \IxDFCodingStandard\PhpCsFixer\Rules::get();
Run it:
vendor/bin/php-cs-fixer fix
PHP_CodeSniffer
Supplementary (optional) formatter.
Create phpcs.xml in your project root:
<?xml version="1.0"?> <ruleset name="My Coding Standard"> <file>app</file> <file>config</file> <file>database</file> <file>routes</file> <file>tests</file> <rule ref="IxDFCodingStandard"/> </ruleset>
On top of the Generic, PSR and Slevomat rulesets, IxDFCodingStandard ships its own sniffs.
Some run by default; some are opt-in. See docs/README.md for the full list and configuration.
Run it:
vendor/bin/phpcbf # fix vendor/bin/phpcs # check (dry-run)
Composer scripts (recommended)
Wire both tools into composer.json so the whole team runs them the same way:
composer cs
cs fixes files in place. Edit composer.json:
{
"scripts": {
"cs": ["@php-cs-fixer", "@phpcbf"],
"phpcbf": "phpcbf -p",
"phpcs": "phpcs -p -s --report-full --report-summary",
"php-cs-fixer": "php-cs-fixer fix --no-interaction --ansi --quiet"
}
}
3. Continuous integration
Run the fixer in CI and commit the result back, so the branch is always formatted without blocking the build.
This repository dogfoods that pattern; copy its workflow as a starting point: .github/workflows/coding-standard.yml.
interaction-design-foundation/coding-standard 适用场景与选型建议
interaction-design-foundation/coding-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 169.32k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 04 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 interaction-design-foundation/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 interaction-design-foundation/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 169.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 15
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-14