简体   繁体   English

用于缩进 PHP 文件的命令行程序

[英]Command-line program to indent PHP files

I'm looking for a indent application to fix all aspects of PHP code formatting - convert spaces, perform indentation in PHP and HTML code, leave HEREDOC alone, etc.我正在寻找一个缩进应用程序来修复 PHP 代码格式的所有方面 - 转换空格,在 PHP 和 HTML 代码中执行缩进,等等。

Please recommend a decent indenter for PHP.请为 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.首先,批量编辑文件的最佳方法是使用 bash 脚本和 vim。

Second, vim indentation is not perfect and is not working always.其次,vim 压痕并不完美,并且始终无法正常工作。 So I had to rather do "=G" manually then review the source.所以我不得不手动执行“=G”然后查看源代码。

Finally, vim's command "retab" in collaboration with tab settings is great if only looking to change white-spaces into tabs.最后,如果只想将空格更改为制表符,vim 的命令“retab”与制表符设置协作非常棒。

I'd like to also point towards an awesome podcasts where I learned more about Vim:我还想指出一个很棒的播客,在那里我了解了更多关于 Vim 的信息:

Squizlabs has develop PHP_CodeSniffer , which tokenizes PHP, JavaScript and CSS files to detect and fix violations of a defined set of coding standards. Squizlabs开发了PHP_CodeSniffer ,它对 PHP、JavaScript 和 CSS 文件进行标记,以检测和修复一组定义的编码标准的违规行为。 It have phpcbf cli, that ensures your code remains clean and consistent.它具有phpcbf cli,可确保您的代码保持干净和一致。 By their definition it should satisfied your need.根据他们的定义,它应该满足您的需求。 Consider read their wiki , for further step.考虑阅读他们的wiki ,以获得进一步的步骤。

2018 answer 2018年答案

Since originally finding solution, I've moved on to use https://styleci.io/ .自从最初找到解决方案以来,我开始使用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我推荐 PHPStorm,它本身不是命令行,但它确实允许指定自定义代码格式并将其应用于多个文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM