2011-06-02 114 views
1

我正在使用checkstyle验证代码的PHP项目中工作。我有读取XML与SimpleXML的代码的一部分的问题,XML是所有大写字母,例如:禁用特定变量的checkstyle验证

$response = simplexml_load_string($xml); 
$code = $response->CODE; // checkstyle won't validate this because it is in uppercase 

这段代码给我警告,因为变量名是大写(变量需要在camelcase)。因为这个,代码中有很多警告。

问题是:我可以禁止检查特定变量或整个代码区域吗?怎么样?

非常感谢。

回答

5

我不知道如何做checkstyle,但PHPCS也可以创建reports in CheckStyle format。所以如果你没有固定使用Checkstyle,你可以切换。使用PHPCS,您可以add pseudo annotations into the code to skip checking,例如在代码

$response = simplexml_load_string($xml); 
// @codingStandardsIgnoreStart 
$code = $response->CODE; 
// @codingStandardsIgnoreEnd 
echo $code->asXml(); 

// @codingStandardsIgnoreFile 

或只是部分也检查http://phpqatools.orghttp://jenkins-php.org/额外的QA工具。

+0

非常感谢您的回复!我做了一些测试,效果非常好,最后我们要切换到PHPCS。 – 2011-06-02 09:44:16