[英]PhpStorm multi line if() statement auto format
假設我們在項目中使用 PHP 並在 80 處進行硬包裝。
我要這個:
if ($text === 'testTestTestTestTestTestTestTestTest' || $text === 'testTestTestTestTestTestTestTestTest' || $text === 'testTestTestTestTestTestTestTestTest') {
$text = 'test';
}
變成這樣:
if ($text === 'testTestTestTestTestTestTestTestTest'
|| $text === 'testTestTestTestTestTestTestTestTest'
|| $text === 'testTestTestTestTestTestTestTestTest')
{
$text = 'test';
}
有什么方法可以配置 PhpStorm,以便在按下 Ctrl + Alt + L時執行此格式化?
我在Settings - Editor - Code Style - PHP - Wrapping and Braces - 'if()' statement中嘗試了一些選項,但沒有幫助。
好像我做錯了什么。 請幫忙。
首先,在 PSR-12 中有一條關於如何格式化這種類型的長表達式的聲明。 在我們的例子中,它應該是這樣的:
if (
$text === 'testTestTestTestTestTestTestTest'
|| $text2 === 'testTestTestTestTestTestTestTestTest'
|| $text3 === 'testTestTestTestTestTestTest'
) {
$text = 'test';
}
要使 PhpStorm 像這樣格式化它:
File | Settings | Editor | Code Style | PHP
File | Settings | Editor | Code Style | PHP
"Set from..." -> PSR-12
Wrapping and Braces
選項卡Binary expressions = Wrap if long
and checkmark to Operation sign on next line
'if()' statement
部分的同一選項卡上,檢查New line before first element
和New line before last element
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.