[英]Import PHP style guides to PhpStorm to automaticlly structure code?
We have a really sloppy codebase and I would like to structure it a bit eg fix all wrongly intended lines and fix such: $sum=1+1
to $sum = 1 + 1
. 我们有一个非常草率的代码库,我想对其进行结构化,例如修复所有错误的行并修复:
$sum=1+1
到$sum = 1 + 1
。
Is there a way to do this? 有没有办法做到这一点? I have a faint memory that I did something similar with IntelliJ but with googles style guides for java.
我记忆犹新,我用IntelliJ做过类似的事情,但是用了Java的Google样式指南。
Generally speaking: your code will not be reformatted automatically (like Visual Studio may do as you type) -- only with your consent (that's the general idea that devs at JetBrains are sticking to at the moment). 一般而言:您的代码不会自动重新格式化(就像Visual Studio可能会在您键入时那样)-仅在您同意的情况下(这是JetBrains的开发人员目前所坚持的一般想法)。 Although current formatting rules are used when you insert some elements from Code Completion popup/Live Template.
尽管当您从“代码完成”弹出窗口/实时模板中插入某些元素时,会使用当前的格式设置规则。
You can invoke code formatter manually at any time via Code | Reformat Code
您可以随时通过
Code | Reformat Code
手动调用代码格式化程序Code | Reformat Code
Code | Reformat Code
. Code | Reformat Code
。
To configure formatting rules -- Settings/Preferences | Editor | Code Style | PHP
配置格式规则-
Settings/Preferences | Editor | Code Style | PHP
Settings/Preferences | Editor | Code Style | PHP
Settings/Preferences | Editor | Code Style | PHP
. Settings/Preferences | Editor | Code Style | PHP
。
It also allows to use some predefined formatting styles (like PEAR, Zend, WordPress, Symfony 2 etc.) by importing it into your current scheme (use
Set from:` clickable link on the right top side of that screen): PEAR, Zend, WordPress, Symfony 2 etc.) by importing it into your current scheme (use
,它还允许使用一些预定义的格式样式(如PEAR, Zend, WordPress, Symfony 2 etc.) by importing it into your current scheme (use
Set from:该屏幕右上角的可点击链接):
https://www.jetbrains.com/help/phpstorm/2016.3/code-style-php.html#d14191e93 https://www.jetbrains.com/help/phpstorm/2016.3/code-style-php.html#d14191e93
PHP language also has support for code re-arrangement ( Arrangement
tab) -- it allows you to specify how your entities/class elements will be placed in your code (fields first then methods; public methods first and private at the end; etc). PHP语言还支持代码重新排列(“
Arrangement
选项卡)-它允许您指定如何将实体/类元素放置在代码中(字段首先是方法,然后是方法;首先是公共方法,最后是私有;等等) 。
Code arrangement can be executed without invoking actual code formatting -- use Code | Rearrange Code
无需调用实际的代码格式即可执行代码排列-使用
Code | Rearrange Code
Code | Rearrange Code
for that. 为此
Code | Rearrange Code
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.