通过访问域预测数组是否在此处总是为空。
PHP | Code smell | Array is always empty at the point of access 建议 Error
没有必要的变量花括号
PHP | Code style | Unnecessary curly braces syntax for variable 建议 Typo
未定义变量
PHP | Undefined symbols | Undefined variable
建议取消勾选 Search for variable’s definition outside the current file
未定义常量
PHP | Undefined symbols | Undefined constant
缺少参数类型声明
PHP | Type compatibility | Missing parameter’s type declaration 建议不高亮
缺少返回值类型声明
PHP | Type compatibility | Missing return type declaration 建议不高亮
代码格式化
Editor > Code Style > PHP
勾选 Align parameter/property names 和 Align tag comments,保证参数名对齐、注解对齐。
安装 PSR-2 规范插件
composer 全局安装
composer global require "squizlabs/php_codesniffer=*"
Languages & Frameworks > PHP > Quality Tools
编辑 PHP_CodeSniffer 配置,找到 phpcs.bat 的位置。
一般默认在 C:\Users<用户名>\AppData\Roaming\Composer\vendor\bin\phpcs.bat
配置 inspection, PHP > Quality tools > PHP_CodeSniffer validation