Visual Studio 代码将如何像 PhpStorm 那样格式化 PHP?
How Visual Studio Code will use to format PHP like PhpStorm?
我已经使用 phpfmt
扩展来缩进代码,这样格式化代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
当我合并它时 return 代码打算出错。我需要像 PhpStorm 那样格式化代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
哪个扩展以及我如何在 Visual Studio 代码中使用它来消除 Visual Studio 代码中的 PHP 预期错误?
您可以使用我在开发环境中使用的以下设置,这些设置最接近您的要求。
将以下内容添加到 VSCode 中的 settings.json
。
//phpfmt
"phpfmt.php_bin": "php",
"phpfmt.passes": [
"AlignPHPCode",
"AlignTypeHint",
"AddMissingParentheses",
"ConvertOpenTagWithEcho",
"DocBlockToComment",
"IndentTernaryConditions",
"JoinToImplode",
"PSR2KeywordsLowerCase",
"PSR2LnAfterNamespace",
"PSR2CurlyOpenNextLine",
"PSR2ModifierVisibilityStaticOrder",
"PSR2SingleEmptyLineAndStripClosingTag",
"ReindentSwitchBlocks",
"RemoveUseLeadingSlash",
"StripExtraCommaInArray",
"SpaceBetweenMethods",
],
"phpfmt.exclude": [
"ReindentComments",
"StripNewlineWithinClassBody"
],
"phpfmt.psr2": false,
对于双数组格式,您可以在设置中找到,如所附图片。
如果您想在 settings.json 中执行此操作,请将 AlignPHPCode 添加到 phpfmt.passes 数组中。
我已经使用 phpfmt
扩展来缩进代码,这样格式化代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
当我合并它时 return 代码打算出错。我需要像 PhpStorm 那样格式化代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
哪个扩展以及我如何在 Visual Studio 代码中使用它来消除 Visual Studio 代码中的 PHP 预期错误?
您可以使用我在开发环境中使用的以下设置,这些设置最接近您的要求。
将以下内容添加到 VSCode 中的 settings.json
。
//phpfmt
"phpfmt.php_bin": "php",
"phpfmt.passes": [
"AlignPHPCode",
"AlignTypeHint",
"AddMissingParentheses",
"ConvertOpenTagWithEcho",
"DocBlockToComment",
"IndentTernaryConditions",
"JoinToImplode",
"PSR2KeywordsLowerCase",
"PSR2LnAfterNamespace",
"PSR2CurlyOpenNextLine",
"PSR2ModifierVisibilityStaticOrder",
"PSR2SingleEmptyLineAndStripClosingTag",
"ReindentSwitchBlocks",
"RemoveUseLeadingSlash",
"StripExtraCommaInArray",
"SpaceBetweenMethods",
],
"phpfmt.exclude": [
"ReindentComments",
"StripNewlineWithinClassBody"
],
"phpfmt.psr2": false,
对于双数组格式,您可以在设置中找到,如所附图片。
如果您想在 settings.json 中执行此操作,请将 AlignPHPCode 添加到 phpfmt.passes 数组中。