hellochef-me/php-styles

HelloChef 分享了 PHP 风格规则给 PHP-CS-Fixer

1.0.9 2023-02-01 12:13 UTC

This package is auto-updated.

Last update: 2024-08-29 15:33:19 UTC


README

HelloChef PHP 代码风格

共享 PHP 风格规则给 PHP-CS-Fixer

Latest Version on Packagist Total Downloads MIT Licensed

安装包

composer require hellochef-me/php-styles

在项目根目录创建并设置配置文件 .php-cs-fixer.php

<?php

return HelloChef\CodeStyles\PhpStyles::style();

可选,你可以将 php-cs-fixer 缓存文件添加到你的 .gitignore

// .gitignore
.php-cs-fixer.cache

按需格式化代码

  • 格式化整个项目
vendor/bin/php-cs-fixer fix .
  • 格式化特定文件
vendor/bin/php-cs-fixer fix Path/To/ExampleFileToFormat.php

在提交时格式化代码

将以下脚本添加到你的 composer.json

"scripts": {
    "post-update-cmd": [
      "cp vendor/hellochef-me/php-styles/pre-commit .git/hooks/pre-commit",
      "chmod a+x .git/hooks/pre-commit"
    ],
    "post-install-cmd": [
      "cp vendor/hellochef-me/php-styles/pre-commit .git/hooks/pre-commit",
      "chmod a+x .git/hooks/pre-commit"
    ],
},