schwarzer/php-code-style

施瓦泽尔IT为PHP-CS-Fixer共享的PHP风格规则

v3.0.0 2021-09-27 05:10 UTC

This package is auto-updated.

Last update: 2024-09-09 20:31:23 UTC


README

需要此包。

composer require "schwarzer/php-code-style" --dev

使用此包

创建PHP-CS-Fixer分文件。

touch .php-cs-fixer.dist.php

最小设置

将以下内容添加到您的.php-cs-fixer.dist.php文件中。

<?php

$classLoader = require __DIR__ . '/vendor/autoload.php';
$classLoader->register(true);

$rules = [
    // 'use-this-to-override' => 'the-default-rules',
];

$finder = PhpCsFixer\Finder::create()
    ->in([
        __DIR__.'/your/source/code',
    ]);

return (new Schwarzer\PhpCs\Styles)($finder, $rules);

我们的Laravel设置

<?php

$classLoader = require __DIR__ . '/vendor/autoload.php';
$classLoader->register(true);

$rules = [
    // 'use-this-to-override' => 'the-default-rules',
];

$finder = PhpCsFixer\Finder::create()
    ->notPath('bootstrap')
    ->notPath('storage')
    ->notPath('vendor')
    ->in(getcwd())
    ->name('*.php')
    ->notName('*.blade.php')
    ->notName('index.php')
    ->notName('server.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return (new Schwarzer\PhpCs\Styles)($finder, $rules);

准备就绪

现在您可以像平常一样使用php-cs-fixer了。

  • php-cs-fixer fix --dry-run
  • php-cs-fixer fix