定制 zhikariz/yii2-fixer 二次开发

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

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

zhikariz/yii2-fixer

最新稳定版本:v1.1.0

Composer 安装命令:

composer require zhikariz/yii2-fixer

包简介

Yii2 Fixer - Code style fixer for Yii2 projects

README 文档

README

Yii2 Fixer is a code style fixer for Yii2 projects. It uses PHP-CS-Fixer under the hood to enforce consistent coding standards.

Installation

Install as a development dependency via Composer:

composer require --dev zhikariz/yii2-fixer

Note: This package requires PHP 8.1+. If your project uses an older PHP version, you can still install it by setting the PHP_CS_FIXER_IGNORE_ENV environment variable:

PHP_CS_FIXER_IGNORE_ENV=1 composer require --dev zhikariz/yii2-fixer

However, the tool will only work on PHP 8.1+ systems.

Or clone the repository and run:

composer install

Usage

Basic Usage

Fix code style in the current directory:

./vendor/bin/yii2-fixer fix

Fix a specific file or directory:

./vendor/bin/yii2-fixer fix app/models/
./vendor/bin/yii2-fixer fix app/models/User.php

Configuration

By default, Yii2 Fixer uses the included fixer.php configuration file. You can specify a custom config file (PHP, JSON or YAML) to override rules:

./vendor/bin/yii2-fixer fix --config custom-config.json

Custom Configuration

Create a custom-config.json file in your project root:

{
  "rules": {
    "@PSR12": true,
    "array_syntax": {
      "syntax": "short"
    },
    "indentation_type": true
  },
  "notPath": ["vendor/*", "node_modules/*", "storage/*", "tests/_output/*"]
}

Or use YAML format (custom-config.yaml):

rules:
  "@PSR12": true
  array_syntax:
    syntax: short
  indentation_type: true
notPath:
  - "vendor/*"
  - "node_modules/*"
  - "storage/*"
  - "tests/_output/*"

Then run:

./vendor/bin/yii2-fixer fix --config custom-config.json
# or
./vendor/bin/yii2-fixer fix --config custom-config.yaml

The configuration file should return a PhpCsFixer\Config instance.

Rules

Yii2 Fixer enforces the following rules:

  • PSR-2 coding standard
  • Short array syntax
  • 4 spaces indentation
  • Single quotes for strings
  • Proper class attribute separation
  • PHPDoc formatting
  • And more...

See fixer.php for the complete list of rules.

Development

To run tests:

./vendor/bin/phpunit

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-24