Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHPCBF一次解决一个问题?_Php_Codesniffer - Fatal编程技术网

如何使用PHPCBF一次解决一个问题?

如何使用PHPCBF一次解决一个问题?,php,codesniffer,Php,Codesniffer,我已经添加了一个PHPCS配置,以便将一些标准纳入遗留项目 我正在使用PSR-2的放松版本作为过渡步骤。现在我想做的是,慢慢地删除排除项,一个接一个地将更改提交到Git中 对于给定的配置,如何运行PHPCBF 在我的规则集中,我有: <arg name="tab-width" value="4"/> <rule ref="PSR2"> <exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>

我已经添加了一个PHPCS配置,以便将一些标准纳入遗留项目

我正在使用PSR-2的放松版本作为过渡步骤。现在我想做的是,慢慢地删除排除项,一个接一个地将更改提交到Git中

对于给定的配置,如何运行PHPCBF

在我的规则集中,我有:

<arg name="tab-width" value="4"/>
<rule ref="PSR2">
    <exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>

    <exclude name="Generic.Files.LineLength.TooLong"/>
    <exclude name="Generic.Formatting.DisallowMultipleStatements.SameLine"/>
    <exclude name="Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma"/>
    <exclude name="Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma"/>
    <!--<exclude name="Generic.PHP.LowerCaseConstant.Found"/>-->
    <!--<exclude name="Generic.PHP.LowerCaseKeyword.Found"/>-->
    <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
    <exclude name="Generic.WhiteSpace.ScopeIndent"/>

    <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>

    <exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody"/>
    <exclude name="PSR2.Classes.ClassDeclaration.SpaceBeforeBrace"/>
    <exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNotAlone"/>
    <exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
    <exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace"/>
    <exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>
    <exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakIndent"/>
    <exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine"/>
    <exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonCASE"/>
    <exclude name="PSR2.ControlStructures.SwitchDeclaration.SpaceBeforeColonDEFAULT"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.Indent"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBrace"/>
    <exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket"/>
    <exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>

    <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps"/>
    <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>
    <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterKeyword"/>
    <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/>
    <exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterBracket"/>
    <exclude name="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace"/>
    <exclude name="Squiz.ControlStructures.ForLoopDeclaration.NoSpaceAfterFirst"/>
    <exclude name="Squiz.ControlStructures.ForLoopDeclaration.NoSpaceAfterSecond"/>
    <exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen"/>
    <exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose"/>
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals"/>
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceAfterDefault"/>
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpenHint"/>
    <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction"/>
    <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
    <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace"/>
    <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterBracket"/>
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen"/>
    <exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose"/>
    <exclude name="Squiz.Scope.MethodScope.Missing"/>
    <exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
    <exclude name="Squiz.WhiteSpace.ScopeClosingBrace.Indent"/>
    <exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EndLine"/>

    <exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed"/>
    <exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpaceBeforeCloseBrace"/>
    <exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment"/>
    <exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses"/>
    <exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
    <exclude name="PSR2.Files.EndFileNewline.NoneFound"/>
    <exclude name="PSR2.Files.EndFileNewline.TooMany"/>
</rule>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

没有一个是正确的。它们只生成PHPCBF的帮助文本。

您只能一次修复整个嗅探中的错误,而不能修复特定的错误消息。因此,您必须运行:

./www/vendor/bin/phpcbf www/application --standard=Generic --sniffs=Generic.PHP.LowerCaseConstant

为了修复
Generic.PHP.LowerCaseConstant
sniff

报告的所有错误,我能够使用排除规则(如上面示例代码中所列)对特定sniff文件中的特定错误消息运行phbcbf。可以在phbcbf命令中直接使用xml文件

phpcbf --standard=path_to_your_ruleset_file.xml
但是,试图通过在命令行中选择特定的嗅探来运行phpcbf不允许我这样做

这是我在自定义规则集文件中拥有的唯一规则

<rule ref="Drupal.Commenting.FunctionComment">
  <exclude name="Drupal.Commenting.FunctionComment.Missing"/>
  <exclude name="Drupal.Commenting.FunctionComment.MissingFile"/>
  <exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
  <exclude name="Drupal.Commenting.FunctionComment.WrongStyle"/>
  <exclude name="Drupal.Commenting.FunctionComment.ParamCommentNewLine"/>
  <exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
  <exclude name="Drupal.Commenting.FunctionComment.SpacingAfter"/>
  <exclude name="Drupal.Commenting.FunctionComment.SpacingAfterParamType"/>
</rule>


请注意,我并没有明确排除所有可能的错误,而是只排除了我运行此代码的代码库中存在的错误。我想修复的唯一错误是我没有包含在排除列表中的错误。

如何使用此方法更改属性?例如,我想使用PSR2.ControlStructures.ControlStructureSpacing,间距值为1而不是0。很容易在ruleset.xml中使用PHPC进行检测,但我无法在phpcbf中找到它。谢谢。@您告诉PHPCBF使用与PHPCS相同的规则集。因此,假设您有一个引用了此PSR2嗅探的规则集,以及您的自定义间距值,如果您只想修复PSR2.ControlStructures.ControlStructureSpactureSpacting,您可以运行:phpcs/path/to/code--standard=/path/to/your/ruleset.xml--sniffs=PSR2.ControlStructures.ControlStructureSpacingThanks@Greg!我把标准变量想成“PSR1”、“PSR2”、“Generic”等,而忽略了我的规则集作为有效的输入。我尝试运行
phpcbf--standard=PSR2--sniffs=PEAR.Functions.FunctionCallSignature path/to/file.php,但得到了“错误:没有注册嗅探”。如果我将标准更改为PEAR,则应用了太多的更改(嗅探)。@Aliance未注册嗅探,因为PSR2标准未使用该嗅探。您需要使用
--standard=PEAR
。我刚刚再次测试了PHPCBF,可以确认它只会修复
PEAR.Functions.FunctionCallSignature
在使用这些参数时发现的问题。使用
phpcs
运行相同的命令,查看将修复的错误列表。
<rule ref="Drupal.Commenting.FunctionComment">
  <exclude name="Drupal.Commenting.FunctionComment.Missing"/>
  <exclude name="Drupal.Commenting.FunctionComment.MissingFile"/>
  <exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
  <exclude name="Drupal.Commenting.FunctionComment.WrongStyle"/>
  <exclude name="Drupal.Commenting.FunctionComment.ParamCommentNewLine"/>
  <exclude name="Drupal.Commenting.FunctionComment.IncorrectParamVarName"/>
  <exclude name="Drupal.Commenting.FunctionComment.SpacingAfter"/>
  <exclude name="Drupal.Commenting.FunctionComment.SpacingAfterParamType"/>
</rule>