comlaude/php-formatter

预配置的PHP格式化工具

1.0.4 2024-06-17 10:49 UTC

This package is auto-updated.

Last update: 2024-09-17 11:15:11 UTC


README

使用php-cs-fixer预配置的PHP格式化工具

Latest Stable Version License

安装

Composer

将以下内容添加到composer.json中的require部分

"comlaude/php-formatter": "^1.0.0"
$ php composer update

或者

$ php composer require comlaude/php-formatter

集成

Lumen

在您的Lumen应用程序的根目录中创建一个config文件夹,并将vendor/comlaude/php-formatter/config/php-formatter.php的内容复制到config/php-formatter.php。

根据您的需求调整属性。

return [
    // A flag to enable/disable caching mode
    'cache' => false,
    // See https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/rules/index.rst for available rules and rulesets
    'rules' => [
        '@PSR2' => true,
        '@DoctrineAnnotation' => true,
        'whitespace_after_comma_in_array' => true,
    ],
    // You can initialises your own ParallelConfig class here with your desired parameters
    // default is set to detect the environment and use the appropriate resources
    'parallel' => PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect(),
    // this is used to call function on configuring a finder as defined here https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/3.0/doc/config.rst
    'finder' => [
        'include'  => [],
        'exclude'  => ['bootstrap', 'vendor', 'storage'],
        'name'     => ['*.php'],
        'notname'  => ['*.blade.php'],
        'in'       => __DIR__ . '/../../../../',
    ];

基本用法

php vendor/bin/php-formatter fix

CI自动化使用

php vendor/bin/php-formatter fix -v --dry-run

许可证

此包是开源软件,根据MIT许可证授权