wunderio/code-quality
Composer 安装命令:
composer require wunderio/code-quality
包简介
Code Quality checker wrapper for GrumPHP
README 文档
README
This composer package will provide some basic code quality checks before committing code by using https://github.com/phpro/grumphp.
It checks only modified files or new files on git commit, but check on all configured
paths can be executed running vendor/bin/grumphp run
This tool only extends GrumPHP. Please read its documentation on how to configure tool itself.
Checks performed
This repository currently has the following checks:
- Shell script exec bits - check_file_permissions
- PHP Drupal CS and PHP Code security - phpcs
- PHP 8.1 Compatibility - php_compatibility
- PHP syntax - php_check_syntax
- Cognitive complexity and other ecs sniffs - ecs
- Yaml syntax - yaml_lint
- Json syntax - json_lint
- Deprecation testing - php_stan
Pre-requisites
- Composer
- PHP >= 8.1
Installation
This needs to be done only once either while creating a project or enabling code checks in existing project.
composer require wunderio/code-quality --dev
cp vendor/wunderio/code-quality/config/grumphp.yml ./grumphp.yml
cp vendor/wunderio/code-quality/config/phpstan.neon ./phpstan.neon
cp vendor/wunderio/code-quality/config/psalm.xml ./psalm.xml
The commit hook for GrumPHP is automatically installed on composer require.
Customization
Configuration
Details of the configuration are broken down into the following sections.
- Parameters – Configuration settings for GrumPHP itself.
- Tasks – External tasks performing code validation and their respective configurations.
- TestSuites
- Extensions
- Events
- Conventions checker
Task parameters
If you need to customize the rules for PHP CodeSniffer then drop in phpcs.xml in the same folder as composer.json and configure grumphp.yml:
parameters: tasks: phpcs: standard: - phpcs.xml
Same applies to any task that uses other configuration file (easy-coding-standards).
Each code quality tool allows you to define at least 3 things:
run_on- Multiple paths that will be checked and files staged must be from same pathignore_patterns- path parts that will exclude files from checkextensions- file extensions of files that should be checked
Please see individual task documentation for more information on what are other configurable options.
Commands
Since GrumPHP is just a CLI tool, these commands can be triggered:
Usage
The pre-commit hook will be automatically run upon executing git commit.
The code scanning can be avoided by git commit --no-verify or git commit -n but is only meant for rare occasions.
You can run the checks manually with: ./vendor/bin/grumphp run
To run specific task from the defined tasks in grumphp.yml, you can define it with --tasks parameter. Example:
./vendor/bin/grumphp run --tasks=phpcs
Usage in Continuous Integration
You can easily use the code quality checkers on your CI (CircleCi/Jenkins/GitLab CI) by adding this line:
./vendor/bin/grumphp run --no-ansi --no-interaction
IDE Integration (optional)
Prerequisites
Minimally Code Quality 2.2.1 is needed because it contains the WunderAll ruleset that groups all Wunder rulesets.
Ubuntu
To install the necessary PHP components without Apache:
sudo apt install php-cli php-tokenizer
macOS
- Install Homebrew if you don't have it installed already (see instructions on https://brew.sh/)
- Install PHP with Homebrew
brew install php
Configuration
Visual Studio Code
- Install the Drupal extension.
- Open the Drupal extension configuration.
- Find "Drupal > Phpcs: Args" and "Drupal > Phpcbf: Args".
- Click "Edit in settings.json" and add:
{
"drupal.phpcs.args": [
"--standard=WunderAll"
],
"drupal.phpcbf.args": [
"--standard=WunderAll"
]
}
PHPCS usage Example in Visual Studio Code:

PhpStorm
Open settings and look for PHP_Codesniffer. Make sure these settings are the same:
Warnings are underlined and you can choose to fix them by right clicking:
Choose the "PHP Code Beautifier and Fixer: fix the whole file"
wunderio/code-quality 适用场景与选型建议
wunderio/code-quality 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112.94k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「git」 「quality」 「hooks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wunderio/code-quality 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wunderio/code-quality 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wunderio/code-quality 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 112.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-05