我试图为phpcs实现其他编码标准。目前,我已经为visual studio代码设置了phpcs,我有以下编码标准
current/path> phpcs -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz and Zend
我想设置此处列出的其他标准:php-fig
例如PSR4
如何为我的开发设定这些标准?
答案 0 :(得分:0)
您可以使用以下命令设置phpcs使用的default_standard:
phpcs --config-set default_standard <value>
或从项目根目录使用composer依赖项管理器时,发出以下命令:
./vendor/bin/phpcs --config-set default_standard <value>
请记住,PS4是自动加载标准,而不是编码标准。
您可以创建自定义的,自己的编码标准,然后您可以尝试安装自定义编码标准:
phpcs --config-set installed_paths <path/to/custom/coding/standard>
或从项目根目录使用composer依赖项管理器时,发出以下命令:
./vendor/bin/phpcs --config-set installed_paths <path/to/custom/coding/standard>
希望它有所帮助。
答案 1 :(得分:0)
通过示例扩展@ Vladd的答案。
我们想说我们要从this repo启用WordPress编码标准。我们可以按照以下步骤操作:
下载文件并将其保存到本地目录。出于某种原因,我希望它与默认的phpcs标准(全局安装)位于同一文件夹中。所以我已将其保存到:C:\Users\USER_NAME\AppData\Roaming\Composer\vendor\wpcs
如果你有git设置,你可以通过访问文件夹(供应商),点击shift +右键点击并在这里打开命令窗口直接将repo克隆到这个文件夹。加载命令提示符后,只需粘贴此代码:
git clone -b master
https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git
wpcs
这会将标准克隆到供应商文件夹中名为wpcs的文件夹中。
下载标准后,您需要让phpcs知道在哪里找到新标准。这个命令完成了这个:
phpcs --config-set installed_paths C:\Users\USER_NAME\AppData\Roaming\Composer\vendor\wpcs
确保更改已下载标准的路径。
您可以使用phpcs -i
命令交叉检查所有已安装的编码标准。你应该看到以下结果:
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress-VIP
您现在可以启用要用于项目的标准。例如。如果我想从默认标准切换到wordpress,我将使用以下命令:
phpcs --config-set default_standard wordpress