我正在开发一个密码工具模块,其中一部分使用base64编码/解码。因此,出于明显的原因,我有许多变量,其中包括术语“base64”。问题是,当我运行PHP_CodeSniffer工具时,它会抛出警告:“变量”"...64“包含数字,但这是不鼓励的”“。
有没有办法告诉PHP_CodeSniffer对这个特定文件忽略这些警告?我确信有一个很好的理由来避免数字,但在这种情况下,我宁愿使用'base64‘而不是’case 76‘.
我就是这样运行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发布于 2011-08-13 04:54:38
在3.2.0版本之前,PHP_CodeSniffer使用了不同的语法来忽略文件中将在4.0版本中删除的部分代码
旧语法:
// @codingStandardsIgnoreStart
/* put your bad code here! */
// @codingStandardsIgnoreEnd这需要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有关更多细节,请参见CodeSniffer文档。
发布于 2011-09-29 01:19:43
在CodeSniffer版本1.3中,您可以在ruleset.xml文件级别上使用ruleset.xml。
https://stackoverflow.com/questions/7048080
复制相似问题