wunderio/code-quality 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wunderio/code-quality

Composer 安装命令:

composer require wunderio/code-quality

包简介

Code Quality checker wrapper for GrumPHP

README 文档

README

CircleCI

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:

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.

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 path
  • ignore_patterns - path parts that will exclude files from check
  • extensions - 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

  1. Install Homebrew if you don't have it installed already (see instructions on https://brew.sh/)
  2. Install PHP with Homebrew
brew install php

Configuration

Visual Studio Code

  1. Install the Drupal extension.
  2. Open the Drupal extension configuration.
  3. Find "Drupal > Phpcs: Args" and "Drupal > Phpcbf: Args".
  4. Click "Edit in settings.json" and add:
{
    "drupal.phpcs.args": [
        "--standard=WunderAll"
    ],
    "drupal.phpcbf.args": [
        "--standard=WunderAll"
    ]
}

PHPCS usage Example in Visual Studio Code: PHPCS Usage Example in VSC

PhpStorm

Open settings and look for PHP_Codesniffer. Make sure these settings are the same: PhpStorm settings PHPCS 1/2

Check the paths and validate: PhpStorm settings PHPCS 2/2

Warnings are underlined and you can choose to fix them by right clicking: How to fix 1/2

Choose the "PHP Code Beautifier and Fixer: fix the whole file" How to fix 2/2

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 27
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-05