是否有任何可以重新格式化 PHP 源代码的免费 cmd 行脚本?

发布于 2024-07-17 11:24:15 字数 115 浏览 14 评论 0原文

我正在使用预提交挂钩来检查我们员工提交的 PHP 源代码,每个人都对结果非常满意。 工作人员一致认为,重新格式化代码以在提交时遵循(可定制的)样式规则将很有用。 是否有任何 FOSS 脚本可以从命令行执行此操作?

I'm using a pre-commit hook to lint-check PHP source submitted by our staff, and everyone's really happy with the results. The staff have agreed it would be useful to have the code re-formatted to follow (customizable) style rules on commit. Are there any FOSS scripts which can do this from the command-line?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

束缚m 2024-07-24 11:24:15

PHP_CodeSniffer 是一个不错的 PEAR 包,但它只嗅探 PHP 文档以检测是否违反编码标准- 它不会修复违规行为或重新格式化文档。 然而,这是一个很棒的软件包,每个 PHP 开发人员至少应该了解 - 也许您可以让您的同事自行清理他们的代码。

您可以按照您希望的方式编辑 PHP_CS 中的嗅探过滤器。 另一方面,我喜欢默认设置,这至少是编写更好代码的良好开端。

PHP_CodeSniffer is a nice PEAR package, but it only sniffs the PHP documents for detecting violations of coding standards - it doesn't fix the violations or re-formats the documents. However, it's a great package that every PHP-developer should at least know about - and maybe you can get your fellow staff members to sanitize their code on their own.

You can edit the sniffing-filter in PHP_CS the way you want it to work. I on the other hand likes the default settings, which is at least a good start for writing better code.

深海少女心 2024-07-24 11:24:15

正在寻找同样的东西,刚刚在 PEAR 存储库中发现了 PHP Beautfier 包:

http://pear .php.net/package/PHP_Beautifier

希望这有帮助!

Was looking for the same thing, just came across the PHP Beautfier package in the PEAR repository:

http://pear.php.net/package/PHP_Beautifier

Hope this helps!

何以笙箫默 2024-07-24 11:24:15

不完全是一个答案,但既然你提出了它,应该有一个命令行 PHP 美化器。 在那之前,您只能使用 sed 来修复选项卡。

问题是,如果不为 PHP 语言编写解析器,就很难编写出您想要的东西。 因此,如果有人要编写这样的工具,它还应该提供 lint 功能,独立于平台并在非常不受限制的许可下发布。

考虑到上述情况,我认为这就是为什么(目前)不存在(我可以找到)的原因。 我将此作为答案发布以感谢您的想法,这也是 CW 的原因。

Not quite an answer, but since you bring it up, there should be a command line PHP beautifier. Until then you're stuck with sed to fix tabs.

The problem is, its very difficult to write something like what you want without writing a parser for the PHP language. So, if someone were to write such a tool, it should also provide lint functionality, be platform independent and released under a very unrestrictive license.

Considering the above, I think that's why one doesn't (currently) exist (that I could find). I'm posting this as an answer to say thanks for the idea, which is also why this is CW.

一身软味 2024-07-24 11:24:15

不在命令行上,但也许有用:PHP/Eclipse 可以进行自动源格式化,我认为您可以一次性在整个项目上运行它。 http://www.phpeclipse.com/

Not on the command-line but perhaps useful: PHP/Eclipse can do auto source formatting and I think you can run it on an entire project in one go. http://www.phpeclipse.com/ .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文