Automatic code formatting for PHP in your editor or CVS/SVN
PhpCodeBeautififier is a free tool for PHP programmers that formats PHP files to get a nice presentation and keeps the programmer sanity. We all programmers have our own way of representing code lines, but when the code is shared amongst many programmers it has to be formatted following some conventions.
PhpCodeBeautifier allows you to specify those patterns you'd like to follow and it will format every file for you. The idea is simple, you continue on being that little unchangeable typer and delegate the "boring" part to that tool. You can work for several companies having diferent coding standards, but you keep always programming your way, look at the exagerated non-sense sample:
It certainly looks better! So with that tool you and your colleagues can work each one following the personal style and when code has to be merged in the community you pass that final code through the Beautifier for getting an homogeneous code, in the way you all have agreed.
PhpCodeBeautifier is available both for Windows and Linux. In the earlier version (0.77) there is a GUI for windows in addition to the command line (though the command line is the only one I am using). That's a shot on how it might look like the pattern definition:
So, now you are thinking. Ok, that's nice, but I have to invoke all the code through the command line/GUI every time? No, keep on using your favorite IDE and integrate it, or just call the tool directly on the versioning system (CVS/SVN). Beautifier is available under the PHPEdit editor, but as I usually work with Eclipse's PHP Development Tool I followed that simple steps to have it running under the "External Tools" (a couple images are worth thousand words):
And that's it.
Update: A sample screenshot on how it's integrated with subversion pre-commit hook.

- ¿Te gustó el post? »
- Vote it (23)
- Add to your favorites

Comentarios sobre Automatic code formatting for PHP in your editor or CVS/SVN
Can you give me a tip how to to this?
You only have to chek in the last screenshot the option "File" and write ${resource_loc}. That overwrites the current working file. But BEWARE! sometimes i have lost a file so I would recommend that you write somthing like ${resource_loc}_beautified to prevent file loss. I am not using this, although certainly is useful.
According to Subversion's manual it is impossible to run such scripts from pre-hooks. CVS can do it though.
Hi Felix,
In our company we are currently launching the code beautifier scripts in the precommit hook. So if the code is not well formatted the commit is cancelled and a message is shown to the programmer.
See it yourself:
http://static.obolog.com/multimedia/fotos/97000/96330/96330-89709.jpg