开发者

Command-line program to indent PHP files

I'm looking for a indent application to开发者_Python百科 fix all aspects of PHP code formatting - convert spaces, perform indentation in PHP and HTML code, leave HEREDOC alone, etc.

Please recommend a decent indenter for PHP.


find . -name '*.php' -printf "echo -e \"G=gg\n:wq\n\" | vim %p\n" | sh


I have found few things. First, the best way to mass-edit files is to use bash scripting and vim.

Second, vim indentation is not perfect and is not working always. So I had to rather do "=G" manually then review the source.

Finally, vim's command "retab" in collaboration with tab settings is great if only looking to change white-spaces into tabs.

I'd like to also point towards an awesome podcasts where I learned more about Vim:

  • http://vimcasts.org/episodes/show-invisibles/
  • http://vimcasts.org/episodes/tabs-and-spaces/
  • http://vimcasts.org/episodes/whitespace-preferences-and-filetypes/
  • http://vimcasts.org/episodes/tidying-whitespace/


Squizlabs has develop PHP_CodeSniffer, which tokenizes PHP, JavaScript and CSS files to detect and fix violations of a defined set of coding standards. It have phpcbf cli, that ensures your code remains clean and consistent. By their definition it should satisfied your need. Consider read their wiki, for further step.


2018 answer

Since originally finding solution, I've moved on to use https://styleci.io/. I am not affiliated with them, but I really like the simplicity and it keeps the project nice and tidy. Doesn't cost anything for my open-source project either.


I'd recomment PHPStorm, its not a command-line per se, but it does allow to specify custom code formatting and apply it to multiple files

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜