Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any free cmd-line scripts which can re-format PHP source-code?

I'm using a pre-commit hook to lint-check PHP source submitted by our staff, and everyone's really happy with the results. The staff have agreed it would be useful to have the code re-formatted to follow (customizable) style rules on commit. Are there any FOSS scripts which can do this from the command-line?

like image 331
Phillip B Oldham Avatar asked Nov 24 '25 06:11

Phillip B Oldham


2 Answers

PHP_CodeSniffer is a nice PEAR package, but it only sniffs the PHP documents for detecting violations of coding standards - it doesn't fix the violations or re-formats the documents. However, it's a great package that every PHP-developer should at least know about - and maybe you can get your fellow staff members to sanitize their code on their own.

You can edit the sniffing-filter in PHP_CS the way you want it to work. I on the other hand likes the default settings, which is at least a good start for writing better code.

like image 113
Björn Avatar answered Nov 26 '25 20:11

Björn


Was looking for the same thing, just came across the PHP Beautfier package in the PEAR repository:

http://pear.php.net/package/PHP_Beautifier

Hope this helps!

like image 45
Gummy Avatar answered Nov 26 '25 21:11

Gummy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!