清理Vscode的缓存
C:\Users\Administrator\AppData\Roaming\Code
删除 Cache 和 CachedData
PHP Debug
settings.json
C:\Users\Administrator\AppData\Roaming\Code\User\settings.json
{
"php.validate.executablePath": "D:\\openresty-1.19.9.1-win64\\php\\php-8.1.4-nts-Win32-vs16-x64\\php.exe",
"workbench.colorTheme": "Default Light+",
"editor.fontSize": 16,
"intelephense.environment.includePaths": [
"../qgmvc/v1.0",
]
}
PHP.ini xdebug
[xdebug]
zend_extension = xdebug
xdebug.remote_enable=on
xdebug.remote_autostart=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9003
xdebug.idekey=vsc
xdebug.mode=debug
xdebug.start_with_request=yes
工作区.json
{
"settings": {
"php.validate.executablePath": "/usr/bin/php",
"workbench.colorTheme": "Default Light+",
"editor.fontSize": 17,
"intelephense.environment.includePaths": [
"/home/wwwroot/xmvc/v5.0",
"/home/wwwroot/xmvc/v5.0/composer/vendor",
"/home/wwwroot/project/yiparts",
],
"php.debug.ideKey" : "vsc",
"php.debug.executablePath": "/usr/bin/php",
"workbench.tree.indent": 24,
"editor.formatOnPaste": true,
"workbench.startupEditor": "none",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"intelephense.telemetry.enabled": false,
"phpcs.enable": true,
"phpcs.executablePath": "/home/qg/.config/composer/vendor/bin/phpcs",
"phpcs.standard": "PSR12",
"phpcs.ignorePatterns": [
"composer/vendor/*",
"cache/*",
"view/*",
"xview/*"
]
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Listen for PHP Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"externalConsole": false,
"pathMappings": {
"/home/wwwroot/project/yiparts": "${workspaceFolder:yiparts}"
}
},
{
"name": "Debug current script in console",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"externalConsole": false,
"port": 9004
}
]
}
}
名字空间
PHP Namespace Resolver
Ctrl + Alt + i 插入对象的 命名空间
psr12规范
规则文件 vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR12/ruleset.xml
#一行最条字符修改为 1200
<rule ref="Generic.Files.LineLength">
<properties>
<!--<property name="lineLimit" value="120"/>-->
<property name="lineLimit" value="1200"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
ps:vscode 插件 phpcs(vscode-phpcs) 加 squizlabs/php_codesniffer 要对 PHP代码做 psr12规范
全局安装
composer global require "squizlabs/php_codesniffer=*"
一般安装到 C:/Users/Administrator/AppData/Roaming/Composer 目录下
确定全局安装路径
composer global config home
改变换行符
vscode ctrl+shinf+p + change end of line -> LF
如果 php -m 下有warning信息会影响 phpcs 版本号的识别
这情况可以修改 phpcs.bat 添加 php 执行参数 -d error-reporting=E_ERROR
@ECHO OFF
setlocal DISABLEDELAYEDEXPANSION
SET BIN_TARGET=%~dp0/phpcs
SET COMPOSER_RUNTIME_BIN_DIR=%~dp0
php -d error_reporting=E_ERROR "%BIN_TARGET%" %*
项目 .vscode 下的 settings.jon
{
"php.validate.executablePath": "E:\\httpserver\\php-8.3.6-Win32-vs16-x64\\php.exe",
"intelephense.environment.php": "E:\\httpserver\\php-8.3.6-Win32-vs16-x64\\php.exe",
"workbench.colorTheme": "Default Light+",
"editor.fontSize": 17,
"intelephense.environment.includePaths": [
"E:\\www\\qgmvc5\\composer\\vendor",
],
"php.debug.executablePath": "",
"workbench.tree.indent": 24,
"editor.formatOnPaste": true,
"workbench.startupEditor": "none",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"intelephense.telemetry.enabled": false,
"phpcs.enable": true,
"phpcs.executablePath": "C:\\Users\\Administrator\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcs",
"phpcs.standard": "PSR12",
"phpcs.ignorePatterns": [
"*/vendor/*",
"*/cache/*",
"*/view/*",
"*/xview/*"
]
}