bitban/php-code-quality-tools
Composer 安装命令:
composer require bitban/php-code-quality-tools
包简介
PHP Code Quality Tools used in Bitban projects.
README 文档
README
These tools may be used to detect and fix some common errors before committing them to the code repository.
Check command reference section for more detailed information.
Installation
If you have not done this yet, add bin directory to composer.json:
composer config bin-dir bin/
It will add something like this to your composer.json file:
"config": { "bin-dir": "bin/" }
For a better experience, we also suggest to configure post-install and post-update script:
"scripts": { "post-install-cmd": [ "Bitban\\PhpCodeQualityTools\\Composer\\ScriptHandler::checkHooks" ], "post-update-cmd": [ "Bitban\\PhpCodeQualityTools\\Composer\\ScriptHandler::checkHooks" ] }
Then, require new dev dependency:
composer require --dev "bitban/php-code-quality-tools:dev-master"
After that, a new command is available from project's root path:
bin/php-cqtools
Command reference
Check Git Hooks
Checks if Git hooks are installed for current project. If not, it gives a hint to install them, but does not take any action automatically.
bin/php-cqtools hooks:check
Install Git Hooks
Installs Git hooks into .git/hooks/. If destination files already exist, the are backed up.
bin/php-cqtools hooks:install
Git hooks managed are:
- pre-commit
- post-checkout
- post-merge
pre-commit hook
It calls code:validate command.
bin/php-cqtools code:validate --only-commited-files
post-checkout hook
It checks whether composer.lock has changed or not. If so, launches composer install command.
bin/php-cqtools hooks:post-checkout <prevCommit> <postCommit> [<projectPath>]
projectPath argument sets path to be processed. Default value is current project base path.
post-merge hook
It has the same behaviour than post-checkout hook.
bin/php-cqtools hooks:post-merge [<projectPath>]
Uninstall Git Hooks
Removes Git hooks from destination path. If backup files exist, they are restored.
bin/php-cqtools hooks:uninstall
Fix Code Style
Fixes code style of files according to defined code style.
It may fix all project files or only files to be commited. This second option is very convinient to fix errors detected in pre-commit hook.
bin/php-cqtools code:fix-codestyle [--dry-run] [--excluded-paths=EXCLUDED_PATHS] [--only-commited-files] [--custom-ruleset=CUSTOM_RULESET] [<projectPath>]
projectPath argument sets path to be processed. Default value is current project base path.
--dry-run option shows diffs without applying any changes to files.
--excluded-paths option sets some paths not to be processed.
--only-commited-files option processes only files scheduled to be commited.
--custom-ruleset option sets phpcs custom ruleset to be used instead of default one
Validate Code
It performs several tasks:
- PHP files:
- Check for syntax errors
- Check that forbidden functions (i.e., var_dump(), empty()) are not commited
- Check whether multibyte string functions are being used
- Check that code complies defined code style recommendations (errors cannot be commited, warnings may be)
- Check that variable usage is right (i.e., use undefined variables, parameters not used, etc.)
- JSON files:
- Check for syntax errors
- Composer related files:
- Check that composer.json is not commited without composer.lock (checked only with --only-commited-files modifier)
bin/php-cqtools code:validate [--excluded-paths=EXCLUDED_PATHS] [--only-commited-files] [--custom-ruleset=CUSTOM_RULESET] [<projectPath>]
projectPath argument sets path to be processed. Default value is current project base path.
--excluded-paths option sets some paths not to be processed.
--only-commited-files option processes only files scheduled to be commited.
--custom-ruleset option sets phpcs custom ruleset to be used instead of default one
Show debug information
Shows debug information about:
- Validation/fix tools installed, such as phpcs, jsonlint, phpcbf
- Project basepath
- Git hooks path
- Git hooks source path
- Commited files
- Excluded paths
- Project files
bin/php-cqtools debug:show [--show-full-paths] [<projectPath]
projectPath argument sets path to be processed. Default value is current project base path.
--show-full-paths option enables full path file listing instead of relative path
This command, may be unavailable in any future versions of these tools, as it has been added for debug purposes.
Run Bitban Lightweight tests
Runs Bitban's framework lightweight tests. It assumes that Bitban's Development VM is up and running, and it has test launcher script run_light_tests.sh installed.
bin/php-cqtools test:run --vmHost[=VMHOST] [<projectPath]
projectPath argument sets path to be processed. Default value is current project base path.
--vmHost=VMHOST option sets Development VM hostname
This command has no use for projects not integrating Bitban's framework.
References
Here are several interesting links with information (and inspiration) about this subject.
- https://carlosbuenosvinos.com/write-your-git-hooks-in-php-and-keep-them-under-git-control/
- https://www.sitepoint.com/writing-php-git-hooks-with-static-review/
- https://github.com/sdieunidou/php-git-hooks
- http://tech.zumba.com/2014/04/14/control-code-quality/
- https://www.sitepoint.com/8-must-have-php-quality-assurance-tools/
- http://phpqatools.org/
- https://github.com/illusori/PHP_Codesniffer-VariableAnalysis/
bitban/php-code-quality-tools 适用场景与选型建议
bitban/php-code-quality-tools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.48k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「git」 「HOOK」 「quality」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitban/php-code-quality-tools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitban/php-code-quality-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitban/php-code-quality-tools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple tool for checking that your PHP classes and methods use PHPDocs (PHP DocBlocks Checker fork).
Easily manage git hooks in your composer config
Taptima PHP-CS-Fixer fixers
Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !
Extensible package of custom rules for PHPStan.
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
统计信息
- 总下载量: 16.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-06