From 0fa195e4d770af8fb23ecf72b1c08a953258da5c Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 8 Dec 2020 17:59:53 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=B7=BB=E5=8A=A0=20php=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=A3=8E=E6=A0=BC=E6=A3=80=E6=B5=8B=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code-style.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/code-style.md b/code-style.md index 6b484a9..09f33a4 100644 --- a/code-style.md +++ b/code-style.md @@ -1,5 +1,7 @@ Git 提交 PHP 代码风格检测配置 +`composer.json` 文件 + ```json { "require": { @@ -31,5 +33,59 @@ Git 提交 PHP 代码风格检测配置 "fix-style": "Run style checks and fix violations." } } +``` + +`.php_cs` 文件 + +```php +setRules([ + '@PSR2' => true, + 'binary_operator_spaces' => true, + 'blank_line_after_opening_tag' => true, + 'compact_nullable_typehint' => true, + 'declare_equal_normalize' => true, + 'lowercase_cast' => true, + 'lowercase_static_reference' => true, + 'new_with_braces' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_leading_import_slash' => true, + 'no_whitespace_in_blank_line' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + ], + ], + 'ordered_imports' => [ + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + 'sort_algorithm' => 'none', + ], + 'return_type_declaration' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + 'single_trait_insert_per_statement' => true, + 'ternary_operator_spaces' => true, + 'unary_operator_spaces' => true, + 'visibility_required' => [ + 'elements' => [ + 'const', + 'method', + 'property', + ], + ], + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude('vendor')//排除的目录 + ->in([__DIR__.'/app/'])//检测的目录,支持多个目录 + ) +; + +``` -``` \ No newline at end of file