多人协同开发,保持统一代码风格
程序员文章站
2022-05-31 19:57:00
...
composer require friendsofphp/php-cs-fixer --dev
根目录 创建 .cs 并且 写入 以下内容
#!/bin/bash
vendor/bin/php-cs-fixer fix
根目录 创建 .php-cs-fixer.php 并且 写入 以下内容
<?php
declare(strict_types=1);
/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:3.0.0-rc.1|configurator
* you can change this configuration by importing this file.
*/
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@PHP80Migration' => true,
'@PHP80Migration:risky' => true,
'@PSR1' => true,
'@PSR2' => true,
'@PhpCsFixer:risky' => true,
'@PhpCsFixer' => true,
'cast_spaces' => ['space'=>'none'],
'date_time_immutable' => true,
'elseif' => false,
'final_class' => true,
'final_public_method_for_abstract_class' => true,
'global_namespace_import' => ['import_classes'=>true],
'increment_style' => false,
'mb_str_functions' => true,
'multiline_whitespace_before_semicolons' => ['strategy'=>'new_line_for_chained_calls'],
'native_function_invocation' => false,
'no_break_comment' => false,
'nullable_type_declaration_for_default_null_value' => true,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert_internal_type' => true,
'php_unit_expectation' => true,
'php_unit_internal_class' => false,
'php_unit_namespaced' => true,
'php_unit_no_expectation_annotation' => true,
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'phpdoc_align' => ['align'=>'left'],
'yoda_style' => false,
])
->setFinder(PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__)
)
->setCacheFile(__DIR__.'/.php-cs-fixer.cache')
;
执行脚本
./.cs
推荐阅读