nextcloud/coding-standard

Nextcloud 代码规范用于php cs fixer

v1.3.1 2024-09-19 09:07 UTC

README

Nextcloud 代码规范用于php cs fixer

安装

将包添加到您的开发依赖项

composer require --dev nextcloud/coding-standard

并创建一个.php-cs-fixer.dist.php,如下所示

<?php

declare(strict_types=1);

require_once './vendor/autoload.php';

use Nextcloud\CodingStandard\Config;

$config = new Config();
$config
	->getFinder()
	->ignoreVCSIgnored(true)
	->notPath('build')
	->notPath('l10n')
	->notPath('src')
	->notPath('vendor')
	->in(__DIR__);
return $config;

要运行修复器,您首先需要安装它。然后您可以运行php-cs-fixer fix以应用所有自动修复。

为了方便,您可以将它添加到composer.json中的scripts部分

{
    "scripts": {
        "cs:check": "php-cs-fixer fix --dry-run --diff",
        "cs:fix": "php-cs-fixer fix"
    }
}

注意:不要忘记在您的构建脚本中排除.php-cs-fixer.dist.php.php-cs-fixer.cache

从v0.x升级到v1.0

在v1.0中,php-cs-fixer从v2更新到v3。您需要稍微调整您的应用程序

  • .php_cs.dist重命名为.php-cs-fixer.dist.php
  • .php-cs-fixer.cache添加到您的忽略文件