定制 tripomatic/php-code-quality 二次开发

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

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

tripomatic/php-code-quality

Composer 安装命令:

composer require tripomatic/php-code-quality

包简介

A set of PHP code quality tools

README 文档

README

A set of PHP code quality tools for VCS.

Tripomatic\PhpCodeQuality allows for automatic PHP code checking while commiting changes in VCS. At the moment Git and Mercurial are supported. The tool can perform the following pre-commit checks:

  1. If both composer.json and composer.lock are versioned it checks whether they are in sync.
  2. All changed or added PHP files are checked for syntax errors with php -l.
  3. All changed or added PHP files are chekced for coding style with PHP-CS-Fixer. This check requires coding style definition file .php_cs in the repository root.

Installation

Install Tripomatic\PhpCodeQuality using Composer:

$ composer require --dev tripomatic/php-code-quality

To setup automatic code checking before every commit add the following line to your pre-commit hook:

php vendor/bin/php-code-quality check-staged-files

The tool automatically detects the repository type (Git, Mercurial) and checks the changes to be commited.

In Git these changes doesn't have to reflect the working tree so the actual changes are fetched to a temporary directory and the files are controlled there. The directory is automatically removed.

Automatic setup with Composer

The pre-commit hooks can be also set-up automatically using Composer's scripts. For instance you can add the following lines to your composer.json:

"scripts": {
	"pre-install-cmd": "sh git/install-hooks.sh",
	"pre-update-cmd": "sh git/install-hooks.sh"
}

And create a git/install-hooks.sh file containing:

#!/bin/sh
ROOT="$(cd "$(dirname "$0")"/..; pwd -P)"

echo "Installing GIT hooks"
rm -rf ${ROOT}/.git/hooks
ln -s ${ROOT}/git/hooks ${ROOT}/.git/hooks
chmod +x ${ROOT}/.git/hooks/*

And finally, create a git/hooks directory and a pre-commit file in it containing:

#!/bin/sh
ROOT="$(cd "$(dirname "$0")"/../..; pwd -P)"

php ${ROOT}/vendor/bin/php-code-quality check-staged-files

The git directory can be added to the repository and that way the pre-commit code-checking hook will be automatically installed on any composer install and composer update.

Other

In case you use tabs for indenting this package contains also an IndentWithTabsFixer for PHP-CS-Fixer. Installing in the .php_cs is easy:

return Symfony\CS\Config\Config::create()
	->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
	->addCustomFixer(new Symfony\CS\Fixer\Contrib\IndentWithTabsFixer())
	->fixers([
	    '-indentation', # turn off the PSR-2 rule
	    'indent_with_tabs',
	]);

A complete example can be the .php_cs for this repository.

License

Tripomatic\PhpCodeQuality is licensed under MIT.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 10
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固