spaceemotion / php-coding-standard
将多个代码质量工具整合到一个二进制文件中,并统一输出。
dev-master
2020-12-15 22:36 UTC
Requires
- php: ^7.1 || ^8.0
- ext-json: *
- composer/xdebug-handler: ^1.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- ergebnis/composer-normalize: ^2.4
- phan/phan: 3.x
- php-parallel-lint/php-parallel-lint: ^1.2
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12
- phpstan/phpstan-strict-rules: ^0.12
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.15.0
- squizlabs/php_codesniffer: ^3.5
- symplify/easy-coding-standard-prefixed: ^9
- vimeo/psalm: ^4.3
Suggests
- ergebnis/composer-normalize: Normalizes composer.json files
- phan/phan: Static analysis (needs php-ast extension)
- php-parallel-lint/php-parallel-lint: Quickly lints the whole codebase for PHP errors
- phpmd/phpmd: Code mess detection
- phpstan/phpstan: Static analysis
- psalm/phar: Static analysis (.phar)
- squizlabs/php_codesniffer: Code style linter + fixer
- symplify/easy-coding-standard: Code style linter + fixer
- symplify/easy-coding-standard-prefixed: Code style linter + fixer (.phar)
- vimeo/psalm: Static analysis
This package is auto-updated.
Last update: 2024-08-31 00:37:04 UTC
README
php-coding-standard (phpcstd)
phpcstd
将各种代码质量工具(例如代码检查和静态分析)整合到一个易于使用的包中,可以在团队和代码库之间共享。
此项目分为两部分
phpcstd
执行所有启用的工具,并为每个文件返回单个错误输出- 在你的项目中,你依赖于一个单一的仓库(例如
acme/coding-standard
),它依赖于phpcstd
并包含各种基本配置(例如 phpmd.xml、ecs.yaml 等)。然后,你的项目依赖于你自己的编码标准。
phpcstd
本身不预装任何工具。你可以查看我的编码标准作为示例。
支持的工具
⭐ = 推荐
入门
composer require-dev spaceemotion/php-coding-standard
这将安装 phpcstd
二进制文件到你的 vendor 文件夹。
通过 .phpcstd(.dist).ini 配置
为了最小化依赖项,phpcstd
使用 .ini 文件进行配置。如果在你的项目文件夹中找不到 .phpcstd.ini
文件,将使用 .phpcstd.dist.ini
文件作为后备(如果可能的话)。
命令选项
Usage:
run [options] [--] [<files>...]
Arguments:
files List of files to parse instead of the configured sources
Options:
-s, --skip=SKIP Disables the list of tools during the run (comma-separated list) (multiple values allowed)
-o, --only=ONLY Only executes the list of tools during the run (comma-separated list) (multiple values allowed)
--continue Run the next check even if the previous one failed
--fix Try to fix any linting errors
--hide-source Hides the "source" lines from console output
--lint-staged Uses "git diff" to determine staged files to lint
--ci Changes the output format to GithubActions for better CI integration
--no-fail Only returns with exit code 0, regardless of any errors/warnings
-h, --help Display help for the given command. When no command is given display help for the run command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
除了直接在配置或作为参数中定义文件/文件夹外,你还可以将列表通过管道传递给它
$ ls -A1 | vendor/bin/phpcstd
Git 钩子
为了避免等待 CI 管道完成,你可以在提交之前使用 Git 钩子运行更改过的文件。
vendor/bin/phpcstd --lint-staged
CI 支持
GitHub Actions
--ci
标志返回一个格式,可以由 GitHubActions 用于注释提交和 PR(见 他们的文档中如何工作)。
开发
使用 Docker
- 使用以下命令启动容器:
GITHUB_PERSONAL_ACCESS_TOKEN=<token> docker-compose up -d --build
- 使用以下命令运行所有命令:
docker-compose exec php <command here>
使用 XDebug
此项目使用 composer/xdebug-handler 通过在启动时禁用 xdebug 来提高性能。要在开发期间启用 XDebug,您需要设置以下环境变量:PHPCSTD_ALLOW_XDEBUG=1
(如他们的 README 中所述)。