werxe / php-cs-fixer-config
Werxe项目的PHP CS Fixer配置
v2.0.0
2021-05-05 21:44 UTC
Requires
- php: ^8.0
- friendsofphp/php-cs-fixer: ^3.0
README
此仓库提供了一个基础配置,用于friendsofphp/php-cs-fixer
,我们用它来验证和强制执行Werxe上编写的PHP代码的单一编码标准。
安装
运行以下命令
composer require --dev werxe/php-cs-fixer-config
用法
现在包已安装,请在项目的根目录创建一个名为.php_cs
或.php_cs.php
的配置文件,并包含以下内容
<?php // Create a new CS Fixer Finder instance $finder = PhpCsFixer\Finder::create()->in(__DIR__); return (new Werxe\PhpCsFixer\Config()) ->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 (new Werxe\PhpCsFixer\Config()) ->setFinder($finder) ;
强制执行PHPUnit测试的编码标准
如果您想在测试中也启用编码标准,可以在Config
类上调用withPHPUnitRules()
方法,如下所示
<?php // Create a new CS Fixer Finder instance $finder = PhpCsFixer\Finder::create()->in(__DIR__); return (new Werxe\PhpCsFixer\Config()) ->setFinder($finder) ->withPHPUnitRules() ;
贡献
感谢您对PHP CS Fixer Config的兴趣。以下是一些贡献方式。
安全
如果您发现任何安全相关的问题,请通过security@werxe.com发送电子邮件,而不是使用问题跟踪器。
许可证
PHP CS Fixer Config遵循MIT许可证(MIT)。有关更多信息,请参阅许可证文件。