PHP编码标准-Visual Studio代码
我正在尝试为PHPC实现其他编码标准。目前,我已经为VisualStudio代码设置了PHPC,并且我有以下编码标准PHP编码标准-Visual Studio代码,php,visual-studio-code,phpcs,Php,Visual Studio Code,Phpcs,我正在尝试为PHPC实现其他编码标准。目前,我已经为VisualStudio代码设置了PHPC,并且我有以下编码标准 current/path> phpcs -i The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend 我想建立以下列出的其他标准: 比如说 如何为我的开发设置这些标准?您可以使用以下命令设置PHPC使用的默认标准: phpcs --config-set default_st
current/path> phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend
我想建立以下列出的其他标准:
比如说
如何为我的开发设置这些标准?您可以使用以下命令设置PHPC使用的默认标准:
phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard>
phpcs——配置设置默认值\u标准
或者从项目根目录使用composer dependency manager时,发出以下命令:
phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard>
/vendor/bin/phpcs——配置设置默认值\u标准
请记住,PS4是自动加载标准,而不是编码标准
您可以创建自己的自定义编码标准,然后尝试安装自定义编码标准:
phpcs --config-set installed_paths <path/to/custom/coding/standard>
phpcs——配置集安装路径
或者从项目根目录使用composer dependency manager时,发出以下命令:
phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard>
/vendor/bin/phpcs——配置集安装路径
希望有帮助。用一个例子扩展@Vladd的答案 假设我们希望从启用WordPress编码标准。我们可以遵循以下步骤:
C:\Users\USER\u NAME\AppData\Roaming\Composer\vendor\wpcs
git克隆-b主机
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git
WPC
这会将标准克隆到供应商文件夹中名为wpcs的文件夹中phpcs--配置集安装路径C:\Users\USER\u NAME\AppData\Roaming\Composer\vendor\wpcs
确保更改下载标准的路径phpcs-i
命令交叉检查所有已安装的编码标准。您应该看到以下结果:
安装的编码标准有MySource、PEAR、PSR1、PSR2、Squiz、Zend、WordPress、WordPress Core、WordPress Docs、WordPress Extra和WordPress VIP
phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set default_standard <value>
./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard>
phpcs——配置设置默认值\u标准wordpress
PHPC实施编码风格标准,如PSR-1和PSR-2。PSR-4是一种自动加载标准,PHPCS将无法强制执行。因此,您已经正确安装了PHPC,但是您需要使用不同的工具(我不确定是哪种工具)添加对其他PSR的支持。我希望当时我有这个答案,可以节省我几个小时。无论如何,我确实学到了更多关于这个话题的知识,@Greg Sherwood reply也帮了我的忙。我认为这是最好的答案,并以我自己的答案为例。