PHP CS Fixer 自定义修复器教程

PHP CS Fixer 自定义修复器教程

php-cs-fixer-custom-fixersA set of custom fixers for PHP CS Fixer项目地址:https://gitcode.com/gh_mirrors/ph/php-cs-fixer-custom-fixers

1. 项目的目录结构及介绍

php-cs-fixer-custom-fixers/
├── CHANGELOG.md
├── LICENSE
├── README.md
├── bootstrap.php
├── composer.json
├── php-cs-fixer.php
├── phpunit.xml
└── src/
    └── Fixers/
        └── ...
└── tests/
    └── ...
  • CHANGELOG.md: 项目更新日志。
  • LICENSE: 项目许可证。
  • README.md: 项目介绍和使用说明。
  • bootstrap.php: 项目启动文件。
  • composer.json: Composer 配置文件。
  • php-cs-fixer.php: PHP CS Fixer 配置文件。
  • phpunit.xml: PHPUnit 配置文件。
  • src/: 包含自定义修复器的源代码。
  • tests/: 包含测试代码。

2. 项目的启动文件介绍

bootstrap.php

bootstrap.php 文件是项目的启动文件,主要用于加载自定义修复器类。在某些情况下,当 PHP CS Fixer 通过 php-cs-fixer/shim 包安装时,可能需要手动加载自定义修复器类。

require __DIR__ . '/vendor/kubawerlos/php-cs-fixer-custom-fixers/bootstrap.php';

3. 项目的配置文件介绍

php-cs-fixer.php

php-cs-fixer.php 文件是 PHP CS Fixer 的配置文件,用于注册和配置自定义修复器。

return (new PhpCsFixer\Config())
    ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
    ->setRules([
        '@PSR2' => true,
        'array_syntax' => ['syntax' => 'short'],
        PhpCsFixerCustomFixers\Fixer\NoLeadingSlashInGlobalNamespaceFixer::name() => true,
        PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer::name() => true,
    ]);
  • registerCustomFixers: 注册自定义修复器。
  • setRules: 设置规则,包括 PSR-2 标准和自定义修复器规则。

通过以上配置,可以确保 PHP CS Fixer 使用自定义修复器进行代码格式化。

php-cs-fixer-custom-fixersA set of custom fixers for PHP CS Fixer项目地址:https://gitcode.com/gh_mirrors/ph/php-cs-fixer-custom-fixers

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丁淳凝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值