我正在使用密码工具模块,其中一部分是使用base64编码/解码.因此,出于显而易见的原因,我有许多变量,其中包括术语"base64".问题是,当我运行PHP_CodeSniffer工具时,它会抛出警告:"变量"... 64"包含数字,但不鼓励这样做".
有没有办法告诉PHP_CodeSniffer忽略这个特定文件的这些警告?我确信有充分的理由避免数字,但在这种情况下,我宁愿使用'base64'而不是'baseSixtyFour' ......
这就是我运行PHP_CodeSniffer的方式:
valorin@gandalf:~/workspace/library$ phpcs --standard=ZEND ./Tools/
FILE: /home/valorin/workspace/library/Tools/Password.php
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 6 WARNING(S) AFFECTING 5 LINE(S)
--------------------------------------------------------------------------------
38 | WARNING | Variable "_bEncryptionBase64" contains numbers but this is
| | discouraged
94 | WARNING | Variable "_bEncryptionBase64" contains numbers but this is
| | discouraged
94 | WARNING | Variable "base64" contains numbers but this is discouraged
95 | WARNING | Variable "base64" contains numbers but this is discouraged
210 | WARNING | Variable "bEncryptionBase64" contains numbers but this is
| | discouraged
251 | WARNING | Variable "bEncryptionBase64" contains numbers but this is
| | discouraged
--------------------------------------------------------------------------------
Time: 1 second, Memory: 7.50Mb
Run Code Online (Sandbox Code Playgroud)
在 3.2.0 版本之前,PHP_CodeSniffer 使用不同的语法来忽略文件中将在 4.0 版本中删除的部分代码
旧语法:
// @codingStandardsIgnoreStart
/* put your bad code here! */
// @codingStandardsIgnoreEnd
Run Code Online (Sandbox Code Playgroud)
这需要 1.2 或更高版本。
新语法:
PHP_CodeSniffer 现在使用// phpcs:disable和// phpcs:enable注释来忽略文件的一部分并// phpcs:ignore忽略一行。
现在,还可以仅禁用或启用特定的错误消息代码、嗅探、嗅探类别或整个编码标准。您应该在评论后指定它们。如果需要,您可以添加注释,解释为什么使用--分隔符禁用和重新启用嗅探。
<?php
/* Example: Ignoring parts of file for all sniffs */
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
/* Example: Ignoring parts of file for only specific sniffs */
// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable
/* Example: Ignoring next line */
// phpcs:ignore
$foo = [1,2,3];
bar($foo, false);
/* Example: Ignoring current line */
$foo = [1,2,3]; // phpcs:ignore
bar($foo, false);
/* Example: Ignoring one line for only specific sniffs */
// phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
$foo = [1,2,3];
bar($foo, false);
/* Example: Optional note */
// phpcs:disable PEAR,Squiz.Arrays -- this isn't our code
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature -- check function calls again
bar($foo,false);
// phpcs:enable -- this is out code again, so turn everything back on
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅PHP_CodeSniffer 的文档。