drupal/coder
Composer 安装命令:
composer require drupal/coder
包简介
Coder is a library to review Drupal code.
关键字:
README 文档
README
Coder is a library for automated Drupal code reviews and coding standard fixes. It defines rules for PHP_CodeSniffer
Built-in support for:
- "Drupal": Coding Standards https://www.drupal.org/coding-standards
- "DrupalPractice": Best practices for Drupal module development
Online documentation: https://www.drupal.org/node/1419980
Note that Javascript support has been removed. To check and fix Javascript files please use ESLint and see the Drupal ESLint documentation.
Local installation in your Drupal project
For collaborating developer teams it makes sense to lock a Coder version with your other development dependencies locally. In your project where you have your composer.json file execute this:
composer require --dev drupal/coder
Then you can run Coder on your custom module code like this:
./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom
To simplify execution it is highly recommended to use a settings file, see below.
Usage
Check Drupal coding standards
./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom
Check Drupal best practices
./vendor/bin/phpcs --standard=DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom
Automatically fix coding standards
./vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml web/modules/custom
Store settings in a phpcs.xml.dist file
In order to save and commit your PHPCS settings to Git you can use a phpcs.xml.dist file in your project like this:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="example"> <description>PHP CodeSniffer configuration for example development.</description> <!-- Check all files in the custom module directory and below. --> <file>web/modules/custom</file> <arg name="extensions" value="php,module,inc,install,test,profile,theme,info,txt,md,yml"/> <rule ref="Drupal"> <!-- Example how you would disable a rule you are not compliant with yet: <exclude name="Drupal.Commenting.Deprecated"/> --> </rule> <rule ref="DrupalPractice"/> <!-- Example how you would disable an external rule you do not like: <rule ref="PEAR.Functions.ValidDefaultValue.NotAtEnd"> <severity>0</severity> </rule> --> </ruleset>
Then you can invoke phpcs without any options and it will read phpcs.xml.dist from the current directory. This can also be useful for Continuous Integration setups. Example:
./vendor/bin/phpcs -p
Working with Editors
Drupal Code Sniffer can be used with various editors.
Editors:
Automated Testing (PHPUnit + PHPCS + PHPStan)
Coder Sniffer comes with a PHPUnit test suite to make sure the sniffs work correctly. Use Composer to install the dependencies:
composer install
Then execute the tests:
./vendor/bin/phpunit
Then execute the coding standards checker on Coder itself:
./vendor/bin/phpcs
Then execute static analysis:
./vendor/bin/phpstan
Contributing
Please create an issue fork and merge request on drupal.org.
Thank you!
Maintainers
- Pieter Frenssen, https://www.drupal.org/u/pfrenssen
- Michael Welford, https://www.drupal.org/u/mikejw
- Klaus Purer, https://www.drupal.org/u/klausi
Credits
Juliette Reinders Folmer and Greg Sherwood, many sniffs are modified copies of their original work on PHPCS.
drupal/coder 适用场景与选型建议
drupal/coder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45.67M 次下载、GitHub Stars 达 30, 最近一次更新时间为 2014 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「standards」 「phpcs」 「code review」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 drupal/coder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drupal/coder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 drupal/coder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
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.
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.
统计信息
- 总下载量: 45.67M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 20
- 依赖项目数: 488
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2014-02-23