user1450553
user1450553

Reputation: 91

Command line tool to apply suggestions provided by PHP Codesniffer

I am looking for a command line tool that applies code formatting suggestions provided by PHP codesniffer into my code base.

There are some cool tools like PHP CodeSniffer plugin to Eclipse but in my use case I need to do this as a batch process rather than a manual task.

Upvotes: 3

Views: 2488

Answers (2)

dardarlt
dardarlt

Reputation: 1209

CodeSniffer in version 2 introduced automatic error fixing. All you have to do is to upgrade your CodeSniffer to version 2 and run it with command:

phpcbf

instead of old phpcs which only list errors

More information: Fixing Errors Automatically

Upvotes: 2

Greg Sherwood
Greg Sherwood

Reputation: 7222

While there isn't anything that will directly fix all issues reported by PHP_CodeSniffer, there is another unrelated project that tries to fix issues rather than report on them. In particular, it tries to make your code conform to the new PSR-1 and PSR-2 standards, which PHP_CodeSniffer is only just adding support for at the moment.

It's not going to fix everything, but it is probably as close as you are going to get to fixing some issues: https://github.com/fabpot/PHP-CS-Fixer

However, I strongly recommend not running batch fixing tools over your codebase. If you want your code to conform to a coding standard, you really need to learn it and just fix the errors over time. There is no reason to fix everything in one hit, and doing so with an automated tool is, in my experience, the best way to break your codebase.

Upvotes: 4

Related Questions