php - Visual Studio Code 将如何使用像 PhpStorm 这样的 PHP 格式?
问题描述
我已经使用phpfmt
扩展来缩进像这样格式化代码的代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
当我合并它时返回代码意图错误。我需要像 PhpStorm 那样格式化代码
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => 'cms',
],
哪个扩展以及如何在 Visual Studio Code 中使用它来消除 Visual Studio Code 中的 PHP 预期错误?
解决方案
您可以使用我用于我的开发环境的以下设置,这将最接近您正在寻找的内容。
将以下内容添加到您settings.json
的 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,
推荐阅读
- location - 使用带有 bukkit 的非实心块获取两个位置之间的距离
- bash - 有没有更好的方法来为每个 case 语句重复调用函数
- phpmailer - 如何强制 PhpMailer 5.2 使用 TLS 1.2
- c++ - 矩阵与线程问题的乘法
- anylogic - 3 波 Covid 的系统动力学 SEIR 感染曲线
- .net-core - Blazor 如何在没有提交按钮的情况下提交表单
- sql - 统计客户端 SQL 的数量
- visual-studio - 如何在 SSAS 表格模型中调试 DAX 公式?
- r - 为 plotreg 变量标签添加上标和下标
- postgresql - 在 PostgreSQL 中对列具有特定值的表添加非空约束