Question

I'm trying to use the Php Code Sniffer plugin in Jenkins. It generates a checkstyle.xml file but there are no errors inside, and I know that I should have.

Here's the containt of my checkstyle.xml :

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

My build.xml file for Jenkins is :

<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>

And when i do it in command line, I have a different result. My command :

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

It generates the same checkstyle.xml with no errors, and a phpcs-checkstyle.tmp which contains the errors.

How can I do to have the results with the errors in my checkstyle.xml file ?

Thanks.

Was it helpful?

Solution

I think your problem is that you are suffering from this bug: http://pear.php.net/bugs/bug.php?id=19930

The bug only occurs in the RC version you are using.

Reverting to the current stable version (1.4.5) should get things working again for you.

OTHER TIPS

I believe that the reason you're having issues when running the command in Jenkins (ant) is because of the wildcard asterisk you're using. The wildcard is expanded by the linux shell, but not by ant.

Try removing the wildcard.

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

If you're concerned that phpcs will run against non-php files, you can pass an extensions parameter: 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>

Though, by default phpcs only checks .inc and .php files anyhow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top