drupol/phpcsfixer-configs-drupal

为 Drupal 7 和 8 提供的基本 PHP CS Fixer 配置。

2.1.0 2023-10-23 07:51 UTC

This package is auto-updated.

Last update: 2024-09-15 14:04:25 UTC


README

Latest Stable Version GitHub stars Total Downloads License Say Thanks! Donate!

PHP CS Fixer Drupal 配置

描述

本包提供了一套[PHP-Cs-Fixer](https://github.com/FriendsOfPHP/PHP CS Fixer)配置对象,可直接用于Drupal项目。

文档

可用的配置对象

  • drupol\PhpCsFixerConfigsDrupal\Config\Drupal7
  • drupol\PhpCsFixerConfigsDrupal\Config\Drupal8

需求

  • PHP >= 8.0
  • friendsofphp/php-cs-fixer >= 3.35

安装

建议使用Composer在项目中的专用composer.json文件中安装PHP CS Fixer Drupal,例如在tools/php-cs-fixer目录下

mkdir -p tools/php-cs-fixer
composer require --dev --working-dir=tools/php-cs-fixer drupol/phpcsfixer-configs-drupal

或使用主composer.json

composer require --dev drupol/phpcsfixer-configs-drupal

配置

假设您已按照上述说明安装了PHP CS Fixer,您现在应在项目的根目录中设置配置文件.php-cs-fixer.php

touch .php-cs-fixer.php

以下示例设置PHP CS Fixer使用Drupal 8/9/10规则

<?php

use drupol\PhpCsFixerConfigsDrupal\Config\Drupal8;

$finder = PhpCsFixer\Finder::create()
  ->in(['web/modules/custom'])
  ->name('*.module')
  ->name('*.inc')
  ->name('*.install')
  ->name('*.test')
  ->name('*.profile')
  ->name('*.theme')
  ->notPath('*.md')
  ->notPath('*.info.yml')
;

$config = new Drupal8();
$config->setFinder($finder);

$rules = $config->getRules();

$config->setRules($rules);
return $config;

有关如何使用高级配置对象的详细信息,请参阅PHP CS Fixer文档

使用方法

假设您已按照上述说明安装了PHP CS Fixer,您可以使用以下命令修复您的Drupal项目

tools/php-cs-fixer/vendor/bin/php-cs-fixer fix

代码质量、测试和基准测试

每次在库中引入更改时,Github Actions都会运行测试和基准测试。

该库使用PHPUnit编写了测试。您可以在tests目录中自由查看它们。运行./vendor/bin/phpunit以触发测试。

在每次提交之前,使用GrumPHP执行一些检查,运行./vendor/bin/grumphp run以手动检查。

贡献

请随意通过发送Github pull requests来为此库做出贡献。我反应相当迅速 :-)