Php_codesniffer: command finished with non-zero exit value 1

Created on 3 Aug 2015  路  12Comments  路  Source: squizlabs/PHP_CodeSniffer

Dear Squizlabs team,

I am using phpcs v 2.0.0a3, I think it's such a great feature for static code analysis
tool in PHP platform.

But i am hitting the wall when I want to writing a report to a file. The report file is created, but there's error statement.
I run "gradle phpcs", and my phpcs task is like here.

task phpcs (type : Exec, description : "Find Coding Standard Violations using PHP_CodeSniffer & Creating a log file for the Continuous Integration Server"){

    executable "$vendorDir/phpcs.bat"
    args "--report=xml", "--report-file=build/logs/phpcs.xml" , "src"
}

The error command is :

:phpcs FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':phpcs'.
> Process 'command './vendor/bin/phpcs.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Please help me figuring out what's wrong in my configurations.
Thanks.

Question

Most helpful comment

If you never want PHPCS to report a non-zero exit code because your build system can't handle it, you can ensure you are at least on version 2.3.1 and then add these args to your command: --runtime-set ignore_errors_on_exit 1 and --runtime-set ignore_warnings_on_exit 1

All 12 comments

The exit code of phpcs command is non-zero, when some errors were found in analyzed code. In my build scripts (on Jenkins + Phing) I'm not using exit code from phpcs command, but rather analyze count of actual errors/warnings in analyzed code and then decide if build should fail or not.

Dear @aik099

Can you elaborate more, How to not use exit code from phpcs command?
I want it to analyze the code and make the report. No use of exit code.

Thanks

If you never want PHPCS to report a non-zero exit code because your build system can't handle it, you can ensure you are at least on version 2.3.1 and then add these args to your command: --runtime-set ignore_errors_on_exit 1 and --runtime-set ignore_warnings_on_exit 1

Dear @gsherwood,
I have tried it, but the error still same.

Here my code phpcs task.

task phpcs (type : Exec, description : "Find Coding Standard Violations using PHP_CodeSniffer & Creating a log file for the Continuous Integration Server"){
    executable "$vendorDir/phpcs.bat"
    args "--report=xml", "--report-file=build/logs/phpcs.xml" , "src", "--runtime-set", "ignore_errors_on_exit", "1", "--runtime-set", "ignore_warnings_on_exit", "1"
}

You said you are on version 2.0.0a3. Did you update to at least version 2.3.1? Ideally, make sure you are on the latest stable version.

Also, I'm not sure how your tasking system works, so I can't tell you if you've specified everything correctly. I suggest running the command directly and making sure the exit code is working the way you expect.

You may also want to have a look at getting the gradle task to ignore exit codes because you don't need it for what you are doing with PHPCS. I've never used gradle, but a quick Google search seems to indicate that ignore exit codes is supported.

@HieronyM , according to https://issues.gradle.org/browse/GRADLE-1554 the Gradle isn't clever enough to allow ignoring exit code of executed task and therefore @gsherwood suggestion should solve your problem.

@gsherwood , How I can find the latest stable version?
And do you have any suggestion how I can update my phpcs version?

Thanks.

It depends on how you installed it in the first place. PEAR? Composer? A git clone? Some OS package manager?

@gsherwood
I'm using Composer to install it, and it embedded in Gradle tasks.
So first the task will install composer, and composer install the require-dev in composer.json file..

If you are installing it new via composer, you should have the latest version. Run phpcs -v to check. If it is old, use composer to update the dependencies manually, or you can install PHPCS globally via composer if you prefer.

@gsherwood
I have updated it into version 2.3.1 and then add these args to my command: --runtime-set ignore_errors_on_exit 1 and --runtime-set ignore_warnings_on_exit 1.
The problem solved

Thanks.

Good news. Thanks for letting me know.

Was this page helpful?
0 / 5 - 0 ratings