hitechnix/php-cs-fixer

自动为项目配置PHP CS Fixer。

v3.0.0 2024-01-30 08:39 UTC

This package is not auto-updated.

Last update: 2024-09-20 06:16:50 UTC


README

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

📦 要求

该软件包需要PHP 8.0+,并遵循FIG标准PSR-4,以确保共享PHP代码之间具有高度的互操作性。

📋 功能

  • 定义您的规则。
  • 分享您的规则。
  • 最小化风险规则。
  • 创建仓库框架。
  • 还有更多!

🔧 安装

使用以下命令安装软件包

composer require hitechnix/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 Hitechnix\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 Hitechnix\PhpCsFixer\Config::create()->setFinder($finder);

📨 消息

希望您觉得这个有用。如果您有任何问题,请创建一个问题。

🔐 安全性

如果您发现任何与安全性相关的问题,请通过support@hitechnix.com发送电子邮件,而不是使用问题跟踪器。

📖 许可证

本软件在BSD 3-Clause许可证下发布。请参阅LICENSE文件或https://opensource.hitechnix.com/LICENSE.txt获取更多信息。

✨ 贡献者

感谢这些出色的人们(emoji key

本项目遵循all-contributors规范。欢迎所有类型的贡献!