kevyworks/laravel-php-cs-fixer

Laravel 5.5+上通过Artisan CLI使用的PHP-CS-Fixer桥梁

2.0.2 2020-03-09 13:12 UTC

This package is auto-updated.

Last update: 2024-09-10 00:48:36 UTC


README

Total Downloads Latest Stable Version Latest Unstable Version License

此包允许在Laravel 5.5+应用程序中直接使用PHP-CS-Fixer来格式化遵循PSR-1和PSR-2编码标准的PHP代码。

重要
在v2中,默认PHP-CS-Fixer配置已更新,以移除对@Symfony规则集的依赖,并更符合Laravel编码风格。
如果需要,您可以在此处找到v1配置。

致谢

bgaze/laravel-php-cs-fixer分支

此包是https://github.com/JackieDo/Artisan-PHP-CS-Fixer的改编副本。
JackieDo表示敬意和衷心的感谢 :-)

提供的功能

  • 直接在Laravel 5.5+项目中安装PHP-CS-Fixer。
  • 通过Laravel Artisan CLI执行PHP-CS-Fixer的命令
    • php-cs-fixer:fix : 修复目录或文件的PHP编码标准。
    • php-cs-fixer:describe : 描述修复器的规则/规则集。
    • php-cs-fixer:version : 显示PHP-CS-Fixer版本。
  • 一个从代码修复文件的辅助器: php_cs_fixer

安装

使用Composer安装此包。

$ composer require bgaze/laravel-php-cs-fixer

要自定义配置,发布它

$ php artisan vendor:publish --tag=bgaze-php-cs-fixer-config

注意
配置不是标准的Laravel配置文件,因为它返回一个\PhpCsFixer\Config实例。
它将被发布到Laravel安装根目录下的.php-cs文件中。

用法

有关更多信息,请参阅PHP-CS-Fixer文档

修复

使用PHP编码标准修复您的代码。

从Artisan CLI

用法

$ php artisan php-cs-fixer:fix [options] [path/to/dir/or/file]

语法

用法

$ php-cs-fixer:fix [options] path1 [path2 path3 ...]

参数

path 目录或文件的路径(允许多个值)。

选项

--allow-risky                    Allow risky fixers.
--dry-run                        Only shows which files would have been modified, leaving your files unchanged.
--stop-on-violation              Stop execution on first violation.
--diff                           Also produce diff for each file.
--using-cache                    Enable cache usage.
--path-mode[=PATH-MODE]          Specify path mode (override|intersection). [default: "override"]
--config[=CONFIG]                The path to a .php-cs-fixer file.
--rules[=RULES]                  The rules to apply for fixer (comma separated).
--cache-file[=CACHE-FILE]        The path to the cache file.
--format[=FORMAT]                To output results in other formats.
--show-progress[=SHOW-PROGRESS]  Type of progress indicator (none|run-in|estimating). [default: "none"]
-h, --help                       Display this help message
-q, --quiet                      Do not output any message
-V, --version                    Display this application version
--ansi                           Force ANSI output
--no-ansi                        Disable ANSI output
-n, --no-interaction             Do not ask any interactive question
    --env[=ENV]                  The environment the command should run under
-v|vv|vvv, --verbose             Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

默认配置文件.php_cs.dist.php_cs

示例

// Only shows which all files in your project would have been modified, leaving your files unchanged.
$ php artisan php-cs-fixer:fix --dry-run

// Really fixes all files in your project.
$ php artisan php-cs-fixer:fix

// Only fixes all files in the `app` directory.
$ php artisan php-cs-fixer:fix app

// Only fixes all files in the `app` directory with specific configuration file.
$ php artisan php-cs-fixer:fix --config="path/to/config/file" app

从PHP代码

php_cs_fixer()辅助器包装了php-cs-fixer:fix命令,并允许从代码中直接修复文件。
它返回命令的退出代码。

用法

// $path : a path or an array of paths.
// $options : an array of options.
php_cs_fixer($path, $options);

示例

// Quick.
php_cs_fixer('path/to/a/file/or/dir');

// Advanced.
php_cs_fixer(['path/to/file/or/dir/1', 'path/to/file/or/dir/2'], [
    '--allow-risky' => true,
    '--dry-run' => true,
    '--config' => 'path/to/a/config/file'
]);

描述规则或集

用法

$ php-cs-fixer:describe name

参数

name 规则/集的名称。

选项

-h, --help            Display this help message
-q, --quiet           Do not output any message
-V, --version         Display this application version
--ansi                Force ANSI output
--no-ansi             Disable ANSI output
-n, --no-interaction  Do not ask any interactive question
--env[=ENV]           The environment the command should run under
-v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

版本

显示已安装的PHP-CS-Fixer版本。

用法

$ php artisan php-cs-fixer:version