maarsson/coding-standard
最新稳定版本:1.2.0
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 different projects.
This package provides shared code quality rulesets and a sync script that applies them to consumer projects in a predictable and consistent way.
Currently supported:
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
Using PHPMD with the installed ruleset
After the sync script runs, phpmd.xml will exist in your project root, but you need to install the PHPMD itself:
composer require --dev phpmd/phpmd
Then run the PHPMD check like this:
./vendor/bin/phpmd . ansi phpmd.xml --suffixes=php --cache --cache-file=.phpmd.cache
Using PHPCS with the installed ruleset
After the sync script runs, phpcs.xml will exist in your project root, but you need to install the PHPCS itself:
composer require --dev squizlabs/php_codesniffer
Then run the PHPCS check like this:
./vendor/bin/phpcs --parallel=4 --standard=phpcs.xml -d memory_limit=1G --cache=.phpcs.cache .
Using PHP-CS-FIXER with the installed ruleset
After the sync script runs, .php-cs-fixer.php will exist in your project root, but you need to install the PHP-CS-FIXER itself:
composer require --dev friendsofphp/php-cs-fixer
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
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09