brackets/code-style-fixer

修复 PHP 代码风格

v1.0.8 2022-03-10 13:15 UTC

This package is auto-updated.

Last update: 2024-09-10 18:59:20 UTC


README

此仓库是 Php Cs Fixer 安装到项目中的源代码。它使用 brainmaestro/composer-git-hooks 和 friendsofphp/php-cs-fixer 来实现其目的,并为这些包创建包装器。

首先,你需要要求此 Composer 包

composer require --dev brackets/code-style-fixer

接下来,你必须在 composer.json 的脚本部分添加此内容

"scripts": {
    ...
    "post-install-cmd": [
        ...
        "[ $COMPOSER_DEV_MODE -eq 0 ] || ./vendor/bin/code-style-fixer.sh git-hooks-add --ignore-lock"
    ],
    "post-update-cmd": [
        ...
        "[ $COMPOSER_DEV_MODE -eq 0 ] || ./vendor/bin/code-style-fixer.sh git-hooks-update"
    ]
}

然后,你必须安装此包

./vendor/bin/code-style-fixer.sh install

现在你应该已经安装了此包,并且每次提交前都会运行修复器。每次推送前也会运行修复器,但仅用于检查是否一切正常。如果不正常,推送将失败。

附加命令

Git 钩

你可以通过以下方式操作 git 钩

./vendor/bin/code-style-fixer.sh git-hooks-add | git-hooks-update | git-hooks-remove | git-hooks-list

这些命令只是 brainmaestro/composer-git-hooks 包的包装器,因此请参阅 https://github.com/BrainMaestro/composer-git-hooks 的说明。

Php Cs Fixer

要手动运行 phpCsFixer 脚本,请使用

./vendor/bin/code-style-fixer.sh fix

你可以使用在 https://github.com/FriendsOfPHP/PHP-CS-Fixer 中定义的所有参数,修复命令只是 php-cs-fixer 的包装器。