使用 PHP_CodeSniffer 忽略特定警告
我正在开发一个密码工具模块,其中一部分是使用 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
I am working on a password tools module, and part of it is using base64 Encoding/Decoding. As a result I have a number of variables which include the term 'base64' for obvious reasons. The problem is that when I run the PHP_CodeSniffer tool, it throws warnings: "Variable "...64" contains numbers but this is discouraged".
Is there any way to tell PHP_CodeSniffer to ignore these warnings for this specific file? I'm sure there is a good reason to avoid numbers, but in this case I'd rather use 'base64' than 'baseSixtyFour'...
This is how I am running 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在版本 3.2.0 之前,PHP_CodeSniffer 使用不同的语法来忽略文件中的部分代码,这些代码将在版本 4.0 中删除
旧语法:
这需要版本 1.2 或更高版本。
新语法:
PHP_CodeSniffer 现在使用
// phpcs:disable
和// phpcs:enable
注释来忽略部分文件和/ /phpcs:ignore
忽略一行。现在,还可以仅禁用或启用特定的错误消息代码、嗅探、嗅探类别或整个编码标准。您应该在注释后指定它们。如果需要,您可以添加注释,解释为什么使用
--
分隔符禁用和重新启用嗅探。有关更多详细信息,请参阅 PHP_CodeSniffer 文档 。
Before version 3.2.0, PHP_CodeSniffer used different syntax for ignoring parts of code from file which will be removed in version 4.0
Old syntax:
This requires version 1.2 or later.
New syntax:
PHP_CodeSniffer is now using
// phpcs:disable
and// phpcs:enable
comments to ignore parts of files and// phpcs:ignore
to ignore one line.Now, it is also possible to only disable or enable specific error message codes, sniffs, categories of sniffs, or entire coding standards. You should specify them after comments. If required, you can add a note explaining why sniffs are being disable and re-enabled by using the
--
separator.For more details see PHP_CodeSniffer's documentation.
在 CodeSniffer 版本 1.3 中,您可以从特定文件中排除特定嗅探: ruleset.xml 文件的级别。
In CodeSniffer version 1.3 you can exclude specific sniffs from specific files at the level of the ruleset.xml file.