定制 bitban/php-code-quality-tools 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bitban/php-code-quality-tools

Composer 安装命令:

composer require bitban/php-code-quality-tools

包简介

PHP Code Quality Tools used in Bitban projects.

README 文档

README

Latest Stable Version License Build Status Coverage Status

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.

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 bitban/php-code-quality-tools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-06