0

我正在考虑从 sublime text 3 更改为 atom,并且我想为 codeigniter 4 PSR12 设置标识标准。

我已经通过 composer 在全球范围内安装了以下软件包:

  1. PHP_CodeSniffer
  2. Codeigniter4-标准
  3. PHP-CS-Fixer

使用以下命令:

composer global require "squizlabs/php_codesniffer=*"
composer global require codeigniter4/codeigniter4-standard
composer global require friendsofphp/php-cs-fixer

最后是:

export PATH="$PATH:$HOME/.composer/vendor/bin"

我还注意到我的可执行文件不在 /home/user/.config/composer 文件夹中,而是在 /home/user/.composer 文件夹中。

也许我在这方面做错了什么......

在 atom 上,我安装了 atom-beautify 和 php-cs-fixer。

在 atom-beautify 上,我的配置如下: 常规设置:

  1. 保存时美化整个文件:选中
  2. 显示加载视图:选中

可执行文件:

PHP-cs-Fixer -> 二进制/脚本路径:

/home/{user}/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer

PHPCBF -> 二进制/脚本路径:

/home/{user}/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf


PHP:
Default Beautifier: PHP-cs-Fixer
Beautify on save: checked
Allow risky rules: no
PHP-CS-Fixer Version: 2
Rules: @PSR12
PHPCBF Standard:
/home/{user}/.composer/vendor/codeigniter4/codeigniter4-standard/CodeIgniter4

最后是我的 atom-beaufity config.cson

    "*":
  "atom-beautify":
    executables:
      php: {}
      "php-cs-fixer":
        path: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
      phpcbf:
        path: "/home/emerson/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf"
    general:
      _analyticsUserId: "{private-data}"
    php:
      beautify_on_save: true
      rules: "@PSR12"
      standard: "/home/emerson/.composer/vendor/codeigniter4/codeigniter4-standard/CodeIgniter4"
  core:
    telemetryConsent: "limited"
  editor:
    showIndentGuide: true
  "exception-reporting":
    userId: "{private-data}"
  "php-cs-fixer":
    executablePath: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
    phpExecutablePath: "/usr/bin/php"

顺便说一句:我还想问一下你们用 php 进行 Web 开发时使用了哪些插件。

非常感谢!

编辑:

我已经成功设置了 PSR12,我将在下面发布我的新 config.cson:

    "*":
  "atom-beautify":
    executables:
      php: {}
      "php-cs-fixer":
        path: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
      phpcbf:
        path: "/home/emerson/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf"
    general:
      _analyticsUserId: "31b3a718-ab3d-4ec3-96e3-6f5d1c2e2c6b"
    php:
      beautify_on_save: true
      standard: "PSR12"
  core:
    telemetryConsent: "limited"
  editor:
    fontSize: 13
    showIndentGuide: true
  "exception-reporting":
    userId: "6ecc9e46-806b-4e85-9867-e66075d62870"
  "php-cs-fixer":
    executablePath: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
    phpExecutablePath: "/usr/bin/php"

现在的问题是 atom 不会“美化”视图上的 php 代码,只会在模型和控制器上“美化”,甚至视图文件也是 .php

4

1 回答 1

0

只需将 PHPCBF 设置为默认美化器并使用以下配置(您必须将可执行路径更改为您的):

"*":
  "atom-beautify":
    css:
      beautify_on_save: true
      indent_size: 4
    executables:
      php: {}
      "php-cs-fixer":
        path: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
      phpcbf:
        path: "/home/emerson/.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf"
    general:
      _analyticsUserId: ""
    php:
      beautify_on_save: true
      default_beautifier: "PHPCBF"
      standard: "PSR12"
  core:
    projectHome: "~/Desktop/Projects/"
    telemetryConsent: "limited"
  editor:
    fontSize: 13
    showIndentGuide: true
    showInvisibles: true
    tabLength: 4
  "exception-reporting":
    userId: ""
  "php-cs-fixer":
    executablePath: "/home/emerson/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer"
    phpExecutablePath: "/usr/bin/php"
于 2020-09-25T11:48:28.723 回答