2017-08-06 5 views
2

私は独自のレガシーコードベースで作業していますが、いくつかの変数はキャメルケースで、他のものはスネークケースです。私はクリーンアップし、キャメルケースの変数名のみを適用したいと思いますが、そのための嗅覚を見つけることはできません。ここに私のカスタムルールセットの内容があります。camelCase変数の命名規則を適用するためには、どのようなスニッフィングを使用する必要がありますか?

The ruleset.xml standard contains 68 sniffs 

Generic (22 sniffs) 
------------------- 
    Generic.Classes.DuplicateClassName 
    Generic.CodeAnalysis.ForLoopShouldBeWhileLoop 
    Generic.CodeAnalysis.UnconditionalIfStatement 
    Generic.CodeAnalysis.UnnecessaryFinalModifier 
    Generic.CodeAnalysis.UnusedFunctionParameter 
    Generic.CodeAnalysis.UselessOverridingMethod 
    Generic.Commenting.Fixme 
    Generic.Commenting.Todo 
    Generic.ControlStructures.InlineControlStructure 
    Generic.Files.ByteOrderMark 
    Generic.Files.LineEndings 
    Generic.Files.LineLength 
    Generic.Formatting.DisallowMultipleStatements 
    Generic.Formatting.NoSpaceAfterCast 
    Generic.Functions.FunctionCallArgumentSpacing 
    Generic.NamingConventions.CamelCapsFunctionName 
    Generic.NamingConventions.UpperCaseConstantName 
    Generic.PHP.DisallowShortOpenTag 
    Generic.PHP.LowerCaseConstant 
    Generic.PHP.LowerCaseKeyword 
    Generic.WhiteSpace.DisallowTabIndent 
    Generic.WhiteSpace.ScopeIndent 

PEAR (5 sniffs) 
--------------- 
    PEAR.Commenting.InlineComment 
    PEAR.Formatting.MultiLineAssignment 
    PEAR.Functions.ValidDefaultValue 
    PEAR.WhiteSpace.ScopeClosingBrace 
    PEAR.WhiteSpace.ScopeIndent 

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 

Squiz (26 sniffs) 
----------------- 
    Squiz.Classes.ValidClassName 
    Squiz.ControlStructures.ControlSignature 
    Squiz.ControlStructures.ForEachLoopDeclaration 
    Squiz.ControlStructures.ForLoopDeclaration 
    Squiz.ControlStructures.LowercaseDeclaration 
    Squiz.Functions.FunctionDeclarationArgumentSpacing 
    Squiz.Functions.FunctionDeclaration 
    Squiz.Functions.LowercaseFunctionKeywords 
    Squiz.Functions.MultiLineFunctionDeclaration 
    Squiz.PHP.CommentedOutCode 
    Squiz.PHP.Eval 
    Squiz.PHP.GlobalKeyword 
    Squiz.PHP.Heredoc 
    Squiz.PHP.InnerFunctions 
    Squiz.PHP.LowercasePHPFunctions 
    Squiz.PHP.NonExecutableCode 
    Squiz.Scope.MethodScope 
    Squiz.Scope.StaticThisUsage 
    Squiz.WhiteSpace.ControlStructureSpacing 
    Squiz.WhiteSpace.ObjectOperatorSpacing 
    Squiz.WhiteSpace.OperatorSpacing 
    Squiz.WhiteSpace.PropertyLabelSpacing 
    Squiz.WhiteSpace.ScopeClosingBrace 
    Squiz.WhiteSpace.ScopeKeywordSpacing 
    Squiz.WhiteSpace.SemicolonSpacing 
    Squiz.WhiteSpace.SuperfluousWhitespace 

答えて

3

Squiz.NamingConventions.ValidVariableNameスニッフィングを使用して変数名を確認することをお勧めします。

この盗聴には現在5つの異なるエラーコードが含まれています。それらのうち3人は、文字列内の変数、メンバー変数、および変数がすべてラクダケースであることをチェックしています。他の2つのコードは、プライベートメンバーのvarsがアンダースコアで始まることを強制します。あなたはPHPCSバージョン3を使用している場合

はただの変数はキャメルケースは、あるルールセットでこれを含まれていることを確認するには、次の

<rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/> 

あなたもメンバーVARSと文字列VARSはキャメルケースされていることを確認したい場合は、

<rule ref="Squiz.NamingConventions.ValidVariableName"/> 
:あなたは全体の多くをしたい場合は

<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"/> 
<rule ref="Squiz.NamingConventions.ValidVariableName.StringNotCamelCaps"/> 

は、これを含める:あなたはバージョン3を使用している場合は、これらを含めます

PHPCSバージョン2では、特定のスニフコードを含めることはできません。そのため、スニッフィング全体を含める必要があります。次に、重大度を0に設定して不要な特定のコードを除外する必要があります。大文字小文字のチェックを行い、バージョン2を使用している場合は、これをルールセットに入れてください:

<rule ref="Squiz.NamingConventions.ValidVariableName"/> 
<rule ref="Squiz.NamingConventions.ValidVariableName.PublicHasUnderscore"> 
    <severity>0</severity> 
</rule> 
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"> 
    <severity>0</severity> 
</rule> 
+0

ありがとうございました。これらのスニフはメソッドの引数には当てはまりません。他の解決策はありますか? –

+0

@TomášVotrubaが申請しなければなりません。私は 'Squiz.NamingConventions.ValidVariableName'スニフの基本的なチェックを行い、同様にメソッド引数を取り上げています。コードが動作していない場合は、プロジェクトにバグを報告するのが最善の方法です。 –

+0

プライベートプロパティは無視されます –

関連する問題