3

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.

Stephtheboss
  • 65
  • 1
  • 1
  • 6

2 Answers2

3

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.

Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24
  • Thanks you Greg, yes it seems to be the same problem. I'm novice with Linux, how can I downgrade the version ? Could you show me the command lines please ? – Stephtheboss May 22 '13 at 08:22
  • It's ok, i found how to do it.
    
    pear uninstall PHP_CodeSniffer
    pear install PHP_CodeSniffer-1.4.5
    
    The generation seems to work, i have to check it. Thank you
    – Stephtheboss May 22 '13 at 09:58
1

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.

Jay Klehr
  • 469
  • 3
  • 7
  • Thanks Jay Klehr, I tried this before but when I launch a build with that, the phpcs build doesn't end. It seems to doing something but I don't know what. (I only have 2 php file to check for my tests). I have it running 15min but I don't think that it's normal. Do I have to do something else ? – Stephtheboss May 22 '13 at 08:14
  • Now that set --extensions=php, it works. I made so many changes that I don't know if I changed something of not. By the way thank you. – Stephtheboss May 22 '13 at 10:00