使用Jenkins和Php代码嗅探器


Using Jenkins and Php Code Sniffer

我试图在Jenkins中使用Php代码嗅探器插件。它生成了一个checkstyle.xml文件,但是里面没有错误,我知道我应该有。

这是我的checkstyle.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.5.0RC2">
</checkstyle>

我的build.xml文件是:

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
 --report-file=${project.basedir}/build/logs/checkstyle.xml
 --standard=Zend
 ${project.basedir}/*.php" />
  </exec>
 </target>

当我在命令行中这样做时,我有一个不同的结果。我的命令:

phpcs --report=checkstyle --report-file=checkstyle.xml --standard=Zend *.php

它生成相同的checkstyle.xml,没有错误,并生成包含错误的phpcs-checkstyle.tmp。

我怎样才能在我的checkstyle.xml文件中有错误的结果?

谢谢。

我认为你的问题是你正在遭受这个bug: http://pear.php.net/bugs/bug.php?id=19930

这个错误只发生在你正在使用的RC版本。

恢复到当前的稳定版本(1.4.5)应该可以让您再次工作。

我认为您在Jenkins (ant)中运行命令时遇到问题的原因是因为您正在使用通配符星号。该通配符由linux shell展开,而不是由ant展开。

尝试删除通配符。

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
      --report-file=${project.basedir}/build/logs/checkstyle.xml
      --standard=Zend
      ${project.basedir}" />
  </exec>
</target>

如果你担心phpcs会在非php文件上运行,你可以传递一个扩展参数:http://pear.php.net/manual/en/package.php.php-codesniffer.advanced-usage.php

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
      --report-file=${project.basedir}/build/logs/checkstyle.xml
      --standard=Zend
      --extensions=php
      ${project.basedir}" />
  </exec>
</target>

但是,默认情况下phpcs只检查.inc和.php文件