zooroyal / coding-standard-source
这是 ZooRoyal 编码标准的源代码包。
Requires
- php: ^8.2.0
- composer-runtime-api: ^2.0
- ext-json: *
- ext-xml: *
- bamarni/composer-bin-plugin: ^1.8
- composer/semver: ^3.4
- dealerdirect/phpcodesniffer-composer-installer: ^1.0.0
- nette/neon: ^3.3
- nikic/php-parser: ^4.18
- php-di/php-di: ^7.0.1
- phpcompatibility/php-compatibility: dev-develop#a8d67148fb990fbf5c2f6166d54bc91cc01fc655
- slevomat/coding-standard: ^8.10.0
- squizlabs/php_codesniffer: ^3.9.0
- symfony/console: ^6.2.8
- symfony/event-dispatcher: ^6.2.2
- symfony/filesystem: ^6.2.0
- symfony/process: ^6.2.0
- thecodingmachine/safe: ^2.5
- webmozart/path-util: ^2.3
Requires (Dev)
- amphp/amp: ^v2.6.2
- amphp/phpunit-util: ^2.0.0
- amphp/process: ^v1.1.4
- brianium/paratest: ^6.11.0
- infection/infection: >=0.27.11
- mockery/mockery: ^1.6.7
- phpunit/phpunit: ^9.6.16
- roave/security-advisories: dev-latest
- sebastianknott/hamcrest-object-accessor: ^3.0.0
Replaces
- zooroyal/coding-standard: 4.3.8
README
ZooRoyal 编码标准源
该仓库包含使用和构建 ZooRoyal 编码标准所需的所有源代码。
它包括
- PHP Code Sniffer 及其配置
- PHP Mess Detector 及其配置
- PHP 复制粘贴检测器
- PHP-Parallel-Lint
- PHPStan - PHP 静态分析工具 及其配置
- ES-LINT 及其配置
- STYLE-LINT 及其配置
此外,src/bin 目录下有一个 PHP 脚本,可用于您选择的持续集成工具。它通过静态代码分析工具搜索您的源代码以找到需要检查的文件。通过使用 -h 选项调用它,可以找到有关其使用的更多信息。
安装(推荐方式)
Docker
ZooRoyal 编码标准设计为作为 Docker 隔离应用程序使用。因此,如果您的系统上有可用的 docker 守护进程,则无需安装。
Composer
如果 ...
- ... 您对 docker 用户体验感到不舒服 ...
- ... 您想将源代码绑定到 ZooRoyal 编码标准的特定版本 ...
... 您可以在 https://github.com/ZooRoyal/coding-standard 找到现成的 composer 包
composer require --dev "zooroyal/coding-standard"
它仍然需要您在系统上拥有可用的 docker 守护进程。
ZooRoyal 编码标准应用程序将在 vendor/bin/coding-standard
下可用。
从源代码安装(不推荐)
如果以上所有方法都失败,您可以从此源代码包中安装 ZooRoyal 编码标准。**请注意,这不建议**。您的项目将需要遵守大量的依赖项。它们将非常具体,并会根据我们的需要而更改。
独立
如果您想将 ZooRoyal 编码标准作为独立应用程序使用,可以使用以下命令
git clone git@github.com:ZooRoyal/coding-standard-source.git
cd coding-standard-source
composer install
ZooRoyal 编码标准应用程序将在 src/bin/coding-standard
下可用。
作为 composer 依赖项
要将 ZooRoyal 编码标准作为 composer 依赖项使用,您可以通过 composer 安装它,但这还不够。您还必须安装必要的工具。为此,您可以使用以下过程
composer require --dev "zooroyal/coding-standard-source"
现在您需要将以下行添加到您的 composer.json 文件中
{ [...] "extra": { [...] "bamarni-bin": { "bin-links": true, "forward-command": true } } [...] }
最后一步是安装必要的工具。这可以通过运行以下命令来完成
cp -r vendor/zooroyal/coding-standard-source/vendor-bin . composer update # If you need Javascript support ... npm install --save-dev vendor/zooroyal/coding-standard-source
这将安装以下工具在 vendor-bin
下的几个目录中
- PHPStan (composer.json)
- PHP-Parallel-Lint (composer.json)
- PHPCPD (composer.json)
- PHPMD (composer.json)
该工具将被安装在 node_modules
ZooRoyal 编码标准应用程序将在 vendor/bin/coding-standard
下可用。
使用 ZooRoyal 编码标准
请注意,ZooRoyal 编码标准只能检查同时是 git 仓库 和 composer 项目 的源代码
直接使用 Docker 镜像
如果您想直接使用 Docker 镜像,可以使用以下命令
docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:latest <parameter>
这将挂载您当前的工作目录作为您要检查的源代码的根目录。
为了方便起见,您可以为这个命令创建一个别名
alias coding-standard="docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:latest"
要使用编码标准的特定版本,只需将版本标签添加到镜像名称中
docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:4.0.0 <parameter>
使用 composer 包
composer 包将在您的 composer 项目的 vendor/bin
文件夹或独立安装文件夹的 src/bin
中安装一个脚本。使用它们来运行 ZooRoyal 编码标准。
ZooRoyal 编码标准应用程序必须从您项目的根目录执行。
使用 ZooRoyal 编码标准
运行命令以获取使用说明。
coding-standard
Available commands:
find-files Finds files for code style checks.
help Displays help for a command
list Lists commands
checks
checks:forbidden-changes Checks for unwanted code changes.
sca
sca:all Run all static code analysis tools.
sca:copy-paste-detect Run PHP-CPD on PHP files.
sca:eslint Run ESLint on JS files.
sca:mess-detect Run PHP-MD on PHP files.
sca:parallel-lint Run Parallel-Lint on PHP files.
sca:sniff Run PHP-CS on PHP files.
sca:stylelint Run StyleLint on Less files.
sca:stan Run PHPStan on PHP files.
示例 sca:all
coding-standard sca:all -h
Usage:
sca:all [options]
Options:
-t, --target=TARGET Finds Files which have changed since the current branch parted from the target
branch only. The Value has to be a commit-ish. [default: false]
-a, --auto-target Finds Files which have changed since the current branch parted from the parent
branch only. It tries to find the parent branch by automagic.
-f, --fix Runs tool to try to fix violations automagically.
-p, --process-isolation Runs all checks in separate processes. Slow but not as resource hungry.
-h, --help Display this help message
-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
Help:
This tool executes all static code analysis tools on files of this project. It ignores files which are in
directories with a .dont<toolshortcut> file. Subdirectories are ignored too.
该 all 命令将所有适用的参数转发到所有已实现的静态代码分析工具。
coding-standard sca:all -a -f
例如,该命令尝试通过自动魔法 (-a) 查找父分支,并告诉所有静态代码分析工具在它们能够的情况下修复找到的违规行为。
coding-standard sca:all -t origin/master
该命令计算与分支 origin/master 的差异,并搜索这些文件中的所有违规。
有关示例,请参阅 .travis.yml
扩展编码标准
如果您想使用自己的工具扩展 ZooRoyal 编码标准,有两篇教程可用
将编码标准集成到 PHPStorm 中
如果您想将 ZooRoyal 编码标准集成到 PHPStorm 中,请参阅 doc/ideConfig 文件夹中的指南。