maarsson/coding-standard
Composer 安装命令:
composer require --dev maarsson/coding-standard
包简介
Centralized custom coding standards applied across my projects
关键字:
README 文档
README
Centralized custom coding standards that can be applied across my different projects.
Note
See also maarsson/dev-tools.
About
This package provides shared code quality rulesets and a sync script that applies them to consumer projects in a predictable and consistent way.
By following the installation steps below, the rulesets are automatically applied after composer install and composer update in your project. This guarantees that all projects use the exact same ruleset versions.
Currently supported:
- PHP Mess Detector (PHPMD) - detect design and complexity issues
- PHP CodeSniffer (PHPCS) - detect coding standard violations
- PHP CS Fixer - automatically enforce modern code style
Requirements
- PHP ^8.4
- Composer
Installation
1. Package installation
Install the package as a development dependency in your project:
composer require --dev maarsson/coding-standard
2. Project configuration (required)
To ensure the coding standards are applied automatically, you must configure Composer scripts in the target project.
2.1. Add a named sync script
In your project’s composer.json add:
{
"scripts": {
"coding-standard:sync": [
"vendor/bin/sync-coding-standards.php"
]
}
}
2.2. Run the sync script on install and update
Extend your project’s composer.json scripts section to include:
{
"scripts": {
"coding-standard:sync": [
"vendor/bin/sync-coding-standards.php"
],
"post-install-cmd": [
"@coding-standard:sync"
],
"post-update-cmd": [
"@coding-standard:sync"
]
}
}
With this setup, the coding standards are applied automatically.
When does it apply?
Once configured, the sync script runs automatically in the following cases:
Automatic execution:
- After composer install
- After composer update
- During CI pipelines that run composer install or composer update
Manual execution:
-
You can also apply the coding standards manually at any time:
composer coding-standard:sync(preferred)or:
./vendor/bin/sync-coding-standards.php(direct execution)
What does the sync script do?
The sync script copies shared ruleset files from the package into the project root.
Currently applied files:
phpmd.xmlphpcs.xml.php-cs-fixer.php
Overwrite behavior
The sync process uses an always overwrite strategy:
- If rulesets already exist in the project root, they will be replaced
- This guarantees all projects use the exact same ruleset
This behavior is intentional and ensures consistency across projects. If you need to customize rules per project, fork this repository or manage overrides outside of this package.
Usage
After the sync script runs, the ruleset files will exist in your project root, but the corresponding tools must also be installed. However if you installed the package via maarsson/dev-tools you don’t need to install these manually. Otherwise run:
composer require --dev phpmd/phpmd composer require --dev squizlabs/php_codesniffer composer require --dev friendsofphp/php-cs-fixer
Note: *.cache should be added to .gitignore.
Using PHPMD with the installed ruleset
Run the PHPMD check for displaying violations like this:
./vendor/bin/phpmd . ansi phpmd.xml --suffixes=php --cache --cache-file=.phpmd.cache
Using PHPCS with the installed ruleset
Then run the PHPCS check for displaying violations like this:
./vendor/bin/phpcs --parallel=4 --standard=phpcs.xml -d memory_limit=1G --cache=.phpcs.cache .
Or run the PHPCBF (comes with the same package) to actually fix violations like this:
./vendor/bin/phpcbf --parallel=4 --standard=phpcs.xml -d memory_limit=1G --cache=.phpcs.cache .
Using PHP-CS-Fixer with the installed ruleset
Then run the PHP-CS-Fixer check for displaying violations like this:
./vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php-cs-fixer.php --cache-file=.php-cs-fixer.cache
Or run the PHP-CS-Fixer to actually fix violations like this:
./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --cache-file=.php-cs-fixer.cache
Troubleshooting
Source file not found
This typically means:
- the package is not installed correctly
- Composer install/update did not complete successfully
Try:
composer install composer coding-standard:sync -vvv
Sync script not executable
Ensure your environment supports running scripts from vendor/bin and that file permissions are preserved.
License
maarsson/coding-standard 适用场景与选型建议
maarsson/coding-standard 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「standards」 「dev」 「qa」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maarsson/coding-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maarsson/coding-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maarsson/coding-standard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP_CodeSniffer custom Sniff for Laravel coding standard
A set of abstractions that define core services provided by the DVSA
This is the ZooRoyal coding standard.
Monolog bridge for PHP Debugbar
Vanio Coding Standard Ruleset for PHP_CodeSniffer.
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09