A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearAutomatically reformatting inherited PHP spaghetti code - page 1
User InfoPosts
Automatically reformatting inherited PHP spaghetti code#1
I've taken over a mixed PHP4/PHP5 project which has been handed down from developer to developer, with each one making things worse. Before I spend too much time on it I'd like to develop a base-standard, with consistent formatting at a minimum.

Can anyone recommend a utility (Linux or Mac OS X preferably) that will reformat the code?

If I can set parameters which influence output (like tab-indentation, brace/bracket placement, when to split array values onto new lines etc.) then that's a benefit, though not crucial.

Preference goes to Open Source tools, though I'd like to know your experiences with purchased software too.

posted date: 2008-12-14 17:23:00


Re: Automatically reformatting inherited PHP spaghetti code#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-14 17:23:01


Re: Automatically reformatting inherited PHP spaghetti code#3
You can do that with Netbeans or with Eclipse PDT, both excellent PHP editors. There's a Format Code option in each, which will reformat a selected file according to your code style preferences. There may be an option to format code in bulk as well.I do recommend that if you do this, do the format and immediately check the code back in with a big fat "REFORMATTING!" comment. Trying to mix in other bug fixes with the reformat makes for nasty-looking diff files to try to decipher down the road.

posted date: 2008-12-14 17:33:00


Re: Automatically reformatting inherited PHP spaghetti code#4
I've used http://www.phpformatter.com/, which is an online tool.

posted date: 2008-12-14 17:47:00


Re: Automatically reformatting inherited PHP spaghetti code#5
Checkout CodeSniffer. I have also used this script

posted date: 2008-12-14 18:18:00


Re: Automatically reformatting inherited PHP spaghetti code#6
In my own searching I found the Wikipedia article on Pretty Print which I think will be useful.

posted date: 2008-12-14 20:38:00


Re: Automatically reformatting inherited PHP spaghetti code#7
I use phptidy: http://cmr.cx/phptidy/https://github.com/cmrcx/phptidyBy design, it's not as aggressive as perltidy, but it's still very useful. It can be configured and will do all the php files in your project as a batch.Update: for a more aggressive, standards-based tool, consider PHP CS Fixer: https://github.com/FriendsOfPhp/PHP-CS-Fixer

posted date: 2009-08-26 09:11:00


Re: Automatically reformatting inherited PHP spaghetti code#8
Something I found recently, which I now love and use all the time. In vim:gg=GThis requires the following configuration option, which you can set in your ~/.vimrc: filetype plugin indent on

posted date: 2012-03-08 20:24:00


Re: Automatically reformatting inherited PHP spaghetti code#9
You can bulk format with Netbeans. Just highlight the files on the side panel and click Source > Format.

posted date: 2014-10-02 16:03:00


Re: Automatically reformatting inherited PHP spaghetti code#10
Project has moved to github.com/cmrcx/phptidy

posted date: 2015-10-07 05:55:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.