简体   繁体   English

Visual Studio Code 将如何使用像 PhpStorm 这样的 PHP 格式?

[英]How Visual Studio Code will use to format PHP like PhpStorm?

I have used phpfmt extension to indent the code which formatted code like this我使用phpfmt扩展来缩进格式化代码的代码

'cms' => [
    'class' => 'yii2mod\cms\Module',
    'controllerNamespace' => 'backend\controllers',
    'defaultRoute' => 'cms',
],

And when I merge it return the code intend error.当我合并它时返回代码意图错误。 I need the code to format like PhpStorm did this我需要像 PhpStorm 那样格式化的代码

'cms'   => [
    'class'               => 'yii2mod\cms\Module',
    'controllerNamespace' => 'backend\controllers',
    'defaultRoute'        => 'cms',
],

Which extension and how I use it in Visual Studio Code to get rid of PHP intended error in Visual Studio Code?哪个扩展以及我如何在 Visual Studio Code 中使用它来消除 Visual Studio Code 中的 PHP 预期错误?

You can use the following settings that i use for my development env, would be closest to what you are looking for.您可以使用我用于我的开发环境的以下设置,最接近您正在寻找的设置。

Add the following into your settings.json in VSCode.将以下内容添加到 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,

For double array formatting you will find in settings like the attached image.对于双数组格式,您可以在附加图像等设置中找到。 在此处输入图片说明

And if you want to do it in settings.json, add AlignPHPCode into phpfmt.passes array.如果您想在 settings.json 中执行此操作,请将 AlignPHPCode 添加到 phpfmt.passes 数组中。 在此处输入图片说明

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

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