Browse Source

:sparkles: 添加 php 代码风格检测配置

nick 5 years ago
parent
commit
0fa195e4d7
1 changed files with 57 additions and 1 deletions
  1. 57 1
      code-style.md

+ 57 - 1
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
+<?php
+
+return PhpCsFixer\Config::create()
+    ->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/'])//检测的目录,支持多个目录
+    )
+;
+
+```
 
-```