✨ 添加 php 代码风格检测配置
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
				
			|||||||
Git 提交 PHP 代码风格检测配置
 | 
					Git 提交 PHP 代码风格检测配置
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					`composer.json` 文件
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```json
 | 
					```json
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	"require": {
 | 
						"require": {
 | 
				
			||||||
@@ -31,5 +33,59 @@ Git 提交 PHP 代码风格检测配置
 | 
				
			|||||||
		"fix-style": "Run style checks and fix violations."
 | 
							"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/'])//检测的目录,支持多个目录
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user