corpus / coding-standard
PHP_CodeSniffer 的 Corpus 编码标准
v0.8.0
2023-11-02 19:15 UTC
Requires
Requires (Dev)
- ext-dom: *
- donatj/drop: ^1.0
- friendsofphp/php-cs-fixer: ^3.14
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-01 17:32:57 UTC
README
Corpus 编码标准为 PHP_CodeSniffer。
需求
- dealerdirect/phpcodesniffer-composer-installer: *
- squizlabs/php_codesniffer: *
- slevomat/coding-standard: ^8.14
- php: >=7.4
安装
使用以下命令安装最新版本
composer require --dev 'corpus/coding-standard'
嗅探器
类: \Corpus\Sniffs\ControlStructures\ClosingBraceNewlineSniff
嗅探器: Corpus.ControlStructures.ClosingBraceNewline
确保所有闭合花括号之后都跟着一个空行。
示例
if( $foo ) { echo $bar; } echo $baz;
变为
if( $foo ) { echo $bar; } echo $baz;
类: \Corpus\Sniffs\ControlStructures\OpeningOneTrueBraceSniff
嗅探器: Corpus.ControlStructures.OpeningOneTrueBrace
确保使用 K&R "一个真正的大括号" 风格。
示例
class Foo { public function bar() { echo "bbq"; } }
变为
class Foo { public function bar() { echo "bbq"; } }
类: \Corpus\Sniffs\General\BinaryOperationNewlineSniff
嗅探器: Corpus.General.BinaryOperationNewline
确保在多行逻辑语句中 &&
和 ||
引导行而不是尾部。
示例
if( $foo && $bar && $baz )}
变为
if( $foo && $bar && $baz )}
类: \Corpus\Sniffs\General\ReturnTrailingNewlineSniff
嗅探器: Corpus.General.ReturnTrailingNewline
确保返回语句和后面的花括号之间没有空白行。
示例
if( $foo == true ){ return 1; }
变为
if( $foo == true ){ return 1; }
类: \Corpus\Sniffs\Methods\ClosureSpacingSniff
嗅探器: Corpus.Methods.ClosureSpacing
在闭包中强制在函数/fn 关键字和开括号之间留空白。
示例
$foo = function ( string $foo ) { echo $foo; }; $bar = fn ( int $bar ) => $bar + 1;
变为
$foo = function( string $foo ) { echo $foo; }; $bar = fn( int $bar ) => $bar + 1;
类: \Corpus\Sniffs\Methods\MethodParameterFormattingSniff
嗅探器: Corpus.Methods.MethodParameterFormatting
设置函数参数的最大长度。通过分成多行来修复。
示例
function Foo( ClosingBraceNewlineSniffTest $closingBraceNewlineSniffTest, OpeningOneTrueBraceSniffTest $openingOneTrueBraceSniffTest ) { }
变为
function Foo( ClosingBraceNewlineSniffTest $closingBraceNewlineSniffTest, OpeningOneTrueBraceSniffTest $openingOneTrueBraceSniffTest ) { }
<?php namespace Corpus\Sniffs\Methods; class MethodParameterFormattingSniff { /** * Maximum line character length after which to break function arguments into newlines */ public $maxLength = 130; }
继承的嗅探器
- Generic.ControlStructures.InlineControlStructure
- Generic.WhiteSpace.DisallowSpaceIndent
- Generic.Files.ByteOrderMark
- Generic.Files.LineEndings
- Generic.PHP.LowerCaseConstant
- Generic.PHP.LowerCaseKeyword
- Generic.PHP.DeprecatedFunctions
- Generic.NamingConventions.UpperCaseConstantName
- Generic.Formatting.NoSpaceAfterCast
- Generic.Functions.OpeningFunctionBraceKernighanRitchie
- PSR2.Files.ClosingTag
- PSR2.Classes.PropertyDeclaration
- PEAR.Functions.ValidDefaultValue
- Squiz.Classes.LowercaseClassKeywords
- Squiz.Classes.SelfMemberReference
- Squiz.Scope.MethodScope
- SlevomatCodingStandard.Namespaces.UnusedUses
- SlevomatCodingStandard.Namespaces.DisallowGroupUse
- SlevomatCodingStandard.Namespaces.MultipleUsesPerLine
- SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash
- SlevomatCodingStandard.Classes.TraitUseDeclaration
- SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure
- SlevomatCodingStandard.Functions.UselessParameterDefaultValue
- SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation
- SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch
- SlevomatCodingStandard.Namespaces.UseFromSameNamespace
- SlevomatCodingStandard.Arrays.TrailingArrayComma
- SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator
- SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator
- SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn
- SlevomatCodingStandard.ControlStructures.UselessTernaryOperator
- SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
- SlevomatCodingStandard.Namespaces.UselessAlias
- SlevomatCodingStandard.PHP.UselessSemicolon
- SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
- SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces
- SlevomatCodingStandard.Variables.UselessVariable
- SlevomatCodingStandard.Operators.SpreadOperatorSpacing
- SlevomatCodingStandard.Classes.ParentCallSpacing
- SlevomatCodingStandard.ControlStructures.NewWithoutParentheses
- SlevomatCodingStandard.Commenting.UselessFunctionDocComment
- SlevomatCodingStandard.Classes.RequireSelfReference
- SlevomatCodingStandard.ControlStructures.NewWithoutParentheses