0

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

I've been evaluating several coding standards fixers to run on our code. This is to perform some auto-fixing on legacy code which uses deprecated things like perl-style comments.

The most useful fixer I have used so far is php-tidy which is found here: http://phptidy.berlios.de/

This tries to conform to the PEAR standard, which is almost exactly what I need, except that I want non-hanging braces for control structures.

Can anyone point me a (linux-based) command-line tool that can apply a fixer to use the ANSI style of braces?:

function nice_brace()
{
    if (isset($nicebrace))
    {
        // I like non-hanging braces
    }
}

Rather than the PEAR/Zend style:

function ugly_brace() {
    if (isset($ugly_brace)) {
        // I find this code harder to read
    }
}

Edit: For others looking for something similar, check this script out: https://raw.github.com/gist/366837/25713637b6f2f9e1ec63abf3233142765df4b931/phpbb-reformat.pl

Many thanks

Community
  • 1
  • 1
user1027562
  • 265
  • 4
  • 13

1 Answers1

2

I use the following command in Vim to fix it

:g/^\s*{\s*$/normal kJ

More details from this stackoverflow question

Community
  • 1
  • 1
Sudar
  • 18,954
  • 30
  • 85
  • 131
  • I never thought of using vim to accomplish this. It is nearly what I want, only I want it the other way around. I will experiment with this and try and find a solution, Thanks! – user1027562 Oct 10 '12 at 08:32
  • `:%s/^\(\s*\).*\zs{\s*$/\r\1{/` This does what I want in vim. However, this is a bit too manual. I would prefer a cli tool so that I can automate the fixer via my Jenkins server. The tool doesn't have to be PHP-specfic – user1027562 Oct 10 '12 at 10:22
  • 1
    I had a brain wave that instead of using vim, I could just use some good old fashioned awk and sed – user1027562 Oct 11 '12 at 07:02
  • Indeed. Put it in a shell file, and there you got your CLI tool. – chtenb Oct 11 '12 at 08:47