grafema-team / grafema-phpcs
php-cs-fixer 的 Grafema 规则
v1.0.0
2023-10-26 12:11 UTC
Requires
- php: >=7.4.30
- friendsofphp/php-cs-fixer: ^3.35
This package is not auto-updated.
Last update: 2024-09-27 14:54:44 UTC
README
一组针对 PHP CS Fixer 的自定义修复程序,特别为 Grafema 设计。
什么是 php-cs-fixer?
php-cs-fixer 或 PHP Coding Standards Fixer 是由 Symfony 的超级牛人团队创建的绝佳工具。
它帮助你的 PHP 代码/仓库遵循你团队定义的特定编码标准。
可用的附加修复程序
- 括号内的空格:此修复程序确保在定义函数、if/else 块或括号的控制结构时,存在起始括号后的空格和结束括号前的空格。规则名称:
GrafemaPHPCS/space_inside_parenthesis
。
安装
PHP CS Fixer:可以通过运行以下命令安装自定义修复程序
composer require --dev grafema-team/grafema-phpcs
用法
在你的 PHP CS Fixer 配置文件(.php-cs-fixer.php
)中注册修复程序并使用它们
<?php $header = <<<'EOF' This file is part of Grafema Projects. EOF; return (new PhpCsFixer\Config()) ->setRiskyAllowed( true ) ->registerCustomFixers( [ new GrafemaPHPCS\Fixer\SpaceInsideParenthesisFixer(), ] ) ->setRules( [ '@DoctrineAnnotation' => true, '@PSR2' => true, '@PhpCsFixer' => true, '@Symfony' => true, 'GrafemaPHPCS/space_inside_parenthesis' => true, 'align_multiline_comment' => true, 'array_syntax' => [ 'syntax' => 'short', ], 'binary_operator_spaces' => [ 'operators' => [ '=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal', ], ], 'blank_line_before_statement' => [ 'statements' => [ 'declare', 'return', 'try', 'while', 'for', 'foreach', 'do', ], ], 'class_attributes_separation' => true, 'combine_consecutive_unsets' => true, 'concat_space' => [ 'spacing' => 'one', ], 'constant_case' => [ 'case' => 'lower', ], 'general_phpdoc_annotation_remove' => [ 'annotations' => [ 'author', ], ], 'global_namespace_import' => [ 'import_classes' => true, 'import_constants' => true, 'import_functions' => true, ], 'header_comment' => [ 'comment_type' => 'PHPDoc', 'header' => $header, 'separate' => 'none', 'location' => 'after_declare_strict', ], 'linebreak_after_opening_tag' => true, 'list_syntax' => [ 'syntax' => 'short', ], 'lowercase_static_reference' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => [ 'strategy' => 'no_multi_line', ], 'no_unused_imports' => true, 'no_useless_else' => true, 'not_operator_with_successor_space' => true, 'ordered_class_elements' => true, 'ordered_imports' => [ 'imports_order' => [ 'class', 'function', 'const', ], 'sort_algorithm' => 'alpha', ], 'phpdoc_align' => [ 'align' => 'vertical', ], 'phpdoc_no_alias_tag' => true, 'phpdoc_separation' => true, 'single_line_comment_style' => [ 'comment_types' => [], ], 'single_quote' => true, 'standardize_not_equals' => true, 'yoda_style' => [ 'always_move_variable' => false, 'equal' => false, 'identical' => false, ], ] ) ->setIndent( ' ' ) ->setFinder( PhpCsFixer\Finder::create() ->exclude( 'documentation' ) ->exclude( 'vendor' ) ->exclude( 'src' ) ->in( __DIR__ ) ) ->setUsingCache( false );
配置完成后,从命令行运行 php-cs-fixer fix
。