# 代码规范
# 代码规范定制
- 遵循PSR12 (opens new window)规范, 在它的基础上定制了betterlife框架的代码规范
- 配置文件: install/phpcs.xml
- 检查工具: composer check-style
- 修复工具: composer fix-style
# vscode 配置
- 安装插件(Extensions): phpcs
- 检查工具: 开发代码使用
- 修改配置(Settings)
- Phpcs: Auto Config Search
- 勾选: true
- Phpcs: Enable
- Phpcs: Show Sources
- Phpcs: Standard
- Edit in settings.json
- Phpcs: Auto Config Search
- 修改配置文件(settings.json):
{ ...... "phpcs.showSources": true, "phpcs.standard": "install/phpcs.xml" }
- 如果本地还有其它PHP工程, "phpcs.standard" 应设置为全路径, 否则打开其它项目, vscode会提示找不到文件: "install/phpcs.xml"
- 安装插件(Extensions): php cs fixer
- 修复工具: 开发代码使用
- 配置说明 (opens new window)
- 修改配置(Settings)
- PHP-cs-fixer: Auto Fix By Semicolon
- 勾选: true
- PHP-cs-fixer: Onsave
- 勾选: true
- PHP-cs-fixer: Auto Fix By Semicolon
- 修改配置文件(settings.json):
{ ...... "php-cs-fixer.autoFixBySemicolon": true, "php-cs-fixer.onsave": true, "[php]": { "editor.defaultFormatter": "junstyle.php-cs-fixer" } }
# 参考资料
- php-fig (opens new window)
- PHP PSR 标准规范 (opens new window)
- PHP The Right Way: 中文版 (opens new window)
- PHP_CodeSniffer (opens new window)
- PHP Quality Assurance (opens new window)
- Pear Coding Standards (opens new window)
- WordPress PHP Coding Standards (opens new window)
- Symfony Coding Standards (opens new window)
- PHPStan (opens new window): finds bugs in your code without writing tests.
介绍 →