andrewholgate / drupalstrict
Drupal Strict:使用 PHP CodeSniffer 严格实施 Drupal 开发的额外编码标准。
v0.1.1
2015-01-31 23:20 UTC
Requires
- php: >=5.2.0
- drupal/coder: ~8.2
- squizlabs/php_codesniffer: ~2.0
This package is not auto-updated.
Last update: 2024-09-28 14:58:11 UTC
README
Drupal Strict 代码审查嗅探器是一系列 PHP CodeSniffer 规则,这些规则强制执行超出在 Coder Sniffer 模块 中找到的 Drupal 7 标准的编码标准。
大多数规则旨在通过标记复杂代码来强制执行更好的编码可读性。
示例
安装
使用 Composer,将以下内容添加到您的 composer.json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/andrewholgate/drupalstrict"
}
],
"require": {
"andrewholgate/drupalstrict": "~0.1"
}
}
然后,您需要使用以下命令将 DrupalStrict 和 Drupal 标准链接到 PHP CodeSniffer 路径:
ln -s $(pwd)/vendor/andrewholgate/drupalstrict/DrupalStrict $(pwd)/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
ln -s $(pwd)/vendor/drupal/coder/coder_sniffer/Drupal $(pwd)/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
用法
您可以通过输入以下内容来使用 Drupal 和 Drupal Strict 标准审查您的项目代码:
./vendor/bin/phpcs --standard=Drupal,DrupalStrict -- /path/to/code/
有关更多配置,请参阅 PHP CodeSniffer 命令行用法。
额外的代码审查规则
还可以安装其他规则以进行额外的代码审查。
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/andrewholgate/drupalstrict"
},
{
"type": "vcs",
"url": "https://github.com/Pheromone/phpcs-security-audit"
},
{
"type": "package",
"package": {
"name": "drupal/drupalpractice",
"version": "8.1.0-beta1",
"type": "library",
"dist": {
"url": "http://ftp.drupal.org/files/projects/drupalpractice-8.x-1.0-beta1.tar.gz",
"type": "tar"
}
}
},
],
"require": {
"andrewholgate/drupalstrict": "~0.1",
"drupal/drupalpractice": "8.1.0-beta1",
"pheromone/phpcs-security-audit": "dev-master"
}
}
然后可以使用以下方式将规则链接:
ln -s $(pwd)/vendor/andrewholgate/drupalstrict/DrupalStrict $(pwd)/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
ln -s $(pwd)/vendor/drupal/coder/coder_sniffer/Drupal $(pwd)/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
ln -s $(pwd)/vendor/drupal/drupalpractice/DrupalPractice $(pwd)/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/
并使用以下命令运行:
./vendor/bin/phpcs --standard=Drupal,DrupalPractice,DrupalStrict,vendor/andrewholgate/drupalstrict/security_ruleset.xml -- /path/to/code/
注意,DrupalStrict 还包含用于 phpcs-security-audit 工具的 ruleset.xml 文件。