everon / coding-standard
Everon 编码规范
3.0.2
2023-08-05 17:15 UTC
Requires
Requires (Dev)
- roave/security-advisories: dev-latest
README
包含200多个嗅探器,以及额外的检查和代码分析(例如检测无法到达的代码、未使用的变量等)。
规则集位于 coding-standard/Everon/ruleset.xml
。
安装
使用 composer 进行安装。
composer require everon/coding-standard --dev
配置
安装后,在 <项目目录>phpcs.xml
下创建自己的规则集。
项目的配置示例。
<?xml version="1.0"?>
<ruleset name="Everon">
<exclude-pattern>*/tests/App/*</exclude-pattern>
<exclude-pattern>*/tests/logs/*</exclude-pattern>
<rule ref="Everon"/>
<rule ref="Everon.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array"
value="src/App=>App,tests/App=>Tests\App"/>
<property name="skipDirs" type="array"
value="tests/App/Generated"/>
<property name="extensions" type="array"
value="php"/>
</properties>
</rule>
</ruleset>
配置 rootNamespaces
将允许嗅探器自动扩展并处理完全限定名(FQCN)。
编码规范使用
规则通过 composer 安装命令自动安装。但如果需要,可以使用 cs-setup
手动运行。执行后,您可以开始使用其他编码规范命令。
vendor/bin/cs-check Checks and reports coding style violations
vendor/bin/cs-fix Fixes coding style violations automatically
vendor/bin/cs-list Show coding standard rules
vendor/bin/cs-setup Execute once to setup coding standard rules
cs-check
默认情况下,它将在 src
目录下查找代码。这可以通过命令行进行覆盖。
vendor/bin/cs-check [<路径>]
cs-fix
默认情况下,它将在 src
目录下查找代码。这可以通过命令行进行覆盖。
vendor/bin/cs-fix [<路径>]
cs-list
列出可用的编码规范规则。
vendor/bin/cs-list
cs-setup
只需运行一次以设置编码规范。通常不需要运行它,因为 composer 安装后命令已经完成了设置。
vendor/bin/cs-setup
嗅探器
The EveronCodingStandard standard contains 118 sniffs
Everon (1 sniff)
-----------------
Everon.Files.TypeNameMatchesFileName
Generic (22 sniffs)
-------------------
Generic.Arrays.DisallowLongArraySyntax
Generic.CodeAnalysis.ForLoopShouldBeWhileLoop
Generic.CodeAnalysis.ForLoopWithTestFunctionCall
Generic.CodeAnalysis.JumbledIncrementer
Generic.CodeAnalysis.UnconditionalIfStatement
Generic.CodeAnalysis.UnnecessaryFinalModifier
Generic.ControlStructures.InlineControlStructure
Generic.Files.ByteOrderMark
Generic.Files.LineEndings
Generic.Files.LineLength
Generic.Formatting.DisallowMultipleStatements
Generic.Formatting.NoSpaceAfterCast
Generic.Functions.FunctionCallArgumentSpacing
Generic.NamingConventions.UpperCaseConstantName
Generic.PHP.DeprecatedFunctions
Generic.PHP.DisallowShortOpenTag
Generic.PHP.ForbiddenFunctions
Generic.PHP.LowerCaseConstant
Generic.PHP.LowerCaseKeyword
Generic.PHP.NoSilencedErrors
Generic.WhiteSpace.DisallowTabIndent
Generic.WhiteSpace.ScopeIndent
PEAR (4 sniffs)
---------------
PEAR.Classes.ClassDeclaration
PEAR.ControlStructures.ControlSignature
PEAR.Functions.ValidDefaultValue
PEAR.NamingConventions.ValidClassName
PSR1 (3 sniffs)
---------------
PSR1.Classes.ClassDeclaration
PSR1.Files.SideEffects
PSR1.Methods.CamelCapsMethodName
PSR2 (12 sniffs)
----------------
PSR2.Classes.ClassDeclaration
PSR2.Classes.PropertyDeclaration
PSR2.ControlStructures.ControlStructureSpacing
PSR2.ControlStructures.ElseIfDeclaration
PSR2.ControlStructures.SwitchDeclaration
PSR2.Files.ClosingTag
PSR2.Files.EndFileNewline
PSR2.Methods.FunctionCallSignature
PSR2.Methods.FunctionClosingBrace
PSR2.Methods.MethodDeclaration
PSR2.Namespaces.NamespaceDeclaration
PSR2.Namespaces.UseDeclaration
SlevomatCodingStandard (50 sniffs)
----------------------------------
SlevomatCodingStandard.Arrays.TrailingArrayComma
SlevomatCodingStandard.Classes.ClassConstantVisibility
SlevomatCodingStandard.Classes.UnusedPrivateElements
SlevomatCodingStandard.Commenting.DisallowOneLinePropertyDocComment
SlevomatCodingStandard.Commenting.DocCommentSpacing
SlevomatCodingStandard.Commenting.EmptyComment
SlevomatCodingStandard.Commenting.ForbiddenAnnotations
SlevomatCodingStandard.Commenting.ForbiddenComments
SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration
SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment
SlevomatCodingStandard.ControlStructures.AssignmentInCondition
SlevomatCodingStandard.ControlStructures.DisallowEmpty
SlevomatCodingStandard.ControlStructures.DisallowEqualOperators
SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator
SlevomatCodingStandard.ControlStructures.DisallowYodaComparison
SlevomatCodingStandard.ControlStructures.EarlyExit
SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses
SlevomatCodingStandard.ControlStructures.NewWithParentheses
SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator
SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator
SlevomatCodingStandard.ControlStructures.RequireYodaComparison
SlevomatCodingStandard.Exceptions.DeadCatch
SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly
SlevomatCodingStandard.Files.TypeNameMatchesFileName
SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
SlevomatCodingStandard.Namespaces.DisallowGroupUse
SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword
SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation
SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions
SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalConstants
SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions
SlevomatCodingStandard.Namespaces.MultipleUsesPerLine
SlevomatCodingStandard.Namespaces.NamespaceDeclaration
SlevomatCodingStandard.Namespaces.NamespaceSpacing
SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile
SlevomatCodingStandard.Namespaces.UnusedUses
SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash
SlevomatCodingStandard.Namespaces.UseFromSameNamespace
SlevomatCodingStandard.Namespaces.UseSpacing
SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators
SlevomatCodingStandard.PHP.ShortList
SlevomatCodingStandard.PHP.TypeCast
SlevomatCodingStandard.TypeHints.DeclareStrictTypes
SlevomatCodingStandard.TypeHints.LongTypeHints
SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing
SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing
SlevomatCodingStandard.TypeHints.TypeHintDeclaration
SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces
Squiz (26 sniffs)
-----------------
Squiz.Arrays.ArrayBracketSpacing
Squiz.Classes.LowercaseClassKeywords
Squiz.Classes.ValidClassName
Squiz.Commenting.DocCommentAlignment
Squiz.ControlStructures.ControlSignature
Squiz.ControlStructures.ForEachLoopDeclaration
Squiz.ControlStructures.ForLoopDeclaration
Squiz.ControlStructures.LowercaseDeclaration
Squiz.Functions.FunctionDeclaration
Squiz.Functions.FunctionDeclarationArgumentSpacing
Squiz.Functions.LowercaseFunctionKeywords
Squiz.Functions.MultiLineFunctionDeclaration
Squiz.Operators.ValidLogicalOperators
Squiz.PHP.Eval
Squiz.PHP.NonExecutableCode
Squiz.Scope.MemberVarScope
Squiz.Scope.MethodScope
Squiz.Scope.StaticThisUsage
Squiz.WhiteSpace.ControlStructureSpacing
Squiz.WhiteSpace.LanguageConstructSpacing
Squiz.WhiteSpace.LogicalOperatorSpacing
Squiz.WhiteSpace.MemberVarSpacing
Squiz.WhiteSpace.ScopeClosingBrace
Squiz.WhiteSpace.ScopeKeywordSpacing
Squiz.WhiteSpace.SemicolonSpacing
Squiz.WhiteSpace.SuperfluousWhitespace