focela/php-cs-fixer

自动配置PHP CS Fixer项目

v3.0.0 2024-06-26 10:05 UTC

This package is auto-updated.

Last update: 2024-09-27 16:28:54 UTC


README

本仓库为friendsofphp/php-cs-fixer提供一个基本配置,我们使用它来验证和强制执行PHP代码的单一编码标准。

安装

composer require --dev focela/php-cs-fixer

快速开始

现在包已安装,请在项目的根目录下创建一个名为.php_cs.php_cs.php.php-cs-fixer.php的配置文件,并包含以下内容

<?php

// Create a new CS Fixer Finder instance
$finder = PhpCsFixer\Finder::create()->in(__DIR__);

return Focela\PhpCsFixer\Config::create()
    ->setFinder($finder);

忽略文件和/或目录

  • 在某些情况下,您可能希望忽略某些文件或目录,以便不进行代码审查。
  • 幸运的是,这很容易实现,您只需要在CS Fixer Finder实例上执行一些调用即可 :)
  • 以下是一个简单的示例,其中我们同时忽略文件和目录
<?php

// Directories to not scan
$excludeDirs = [
    'vendor/',
];

// Files to not scan
$excludeFiles = [
    'config/app.php',
];

// Create a new CS Fixer Finder instance
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude($excludeDirs)
    ->ignoreDotFiles(true)
    ->ignoreVCS(true)
    ->filter(function (\SplFileInfo $file) use ($excludeFiles) {
        return ! in_array($file->getRelativePathName(), $excludeFiles);
    });

return Focela\PhpCsFixer\Config::create()->setFinder($finder);

贡献

我们鼓励并支持一个活跃、健康的贡献者社区——包括您!详细信息请参阅贡献指南行为准则。php-cs-fixer维护者会关注问题和拉取请求,但您也可以通过opensource@focela.com报告任何不良行为。该电子邮件列表是一个私人、安全的空间;即使php-cs-fixer维护者也无法访问,因此请毫不犹豫地对我们提出高标准。

MIT许可证下发布。