nexoBlogs network
Anonymous Anonymous

Automatic code formatting for PHP in your editor or CVS/SVN

Monday, 28 de May del 2007
filed under , ,

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:

Sample of phpCodeBeautifier 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: PHPCodebeautifier 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): Eclipse external tools Eclipse external tools

And that's it.

Update: A sample screenshot on how it's integrated with subversion pre-commit hook.

Precommit hook sample

Related to Automatic code formatting for PHP in your editor or CVS/SVN

Comentarios sobre Automatic code formatting for PHP in your editor or CVS/SVN

I also use eclipse as IDE, but I have a problem using your configuration. If I use the same arguments eclipse prints the generated output in the console, but I want to rewrite my current file and force eclipse to reload it afterwards.

Can you give me a tip how to to this?
Yes Nils,

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.
Felix Ogg Felix Ogg

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

Leave your comment about Automatic code formatting for PHP in your editor or CVS/SVN

Leave your comment
You need javascript to be activated on irder to leave comments

Login in OboLog, or create free blog if you don't have one yet.

Then we'll remember your data and show your avatar in your comments.

Sponsors

Login

Otros blogs de nexoBlogs: