Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2019-01-08 13:26:02

I have used phpfmt extension to indent the code which formatted code like this

'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

'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?

Questioner
rajwa766
Viewed
0
Reborn 2019-01-10 00:53:43

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.

//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,