zebra-north / phpcs-short-types
在注释中要求使用短标量类型名称(bool, int),而不是长名称(boolean, integer)。
v1.0.1
2021-12-20 20:01 UTC
Requires
- php: >=7.0
README
PHP Codesniffer 要求使用长形式书写标量类型,例如 boolean
或 integer
。
从 PHP 7+ 开始,标量必须使用短形式书写,例如 bool
或 int
。
此补丁允许你在文档块注释中使用短形式。
之前
/** * Test function. * * @param integer $test A numeric argument. * * @return boolean Returns true or false. */ function test(int $test): bool { return false; }
之后
/** * Test function. * * @param int $test A numeric argument. * * @return bool Returns true or false. */ function test(int $test): bool { return false; }
错误修复
- Squiz.Commenting.FunctionComment.IncorrectParamVarName
- 期望 "boolean" 但找到 "bool" 作为参数类型
- 期望 "integer" 但找到 "int" 作为参数类型
- Squiz.Commenting.VariableComment.IncorrectVarType
- 期望 "boolean" 但找到 "bool" 作为成员变量注释中的 @var 标签
- 期望 "integer" 但找到 "int" 作为成员变量注释中的 @var 标签
- Squiz.Commenting.FunctionComment.InvalidReturn
- 期望 "boolean" 但找到 "bool" 作为函数返回类型
- 期望 "integer" 但找到 "int" 作为函数返回类型
安装
- 使用以下命令安装到 composer 中:
composer require --dev zebra-north/phpcs-short-types
- 编辑你的项目中的
phpcs.xml
以添加引导文件
<?xml version="1.0"?> <ruleset> <arg name="bootstrap" value="vendor/zebra-north/phpcs-short-types/short-types.php"/> ... </ruleset>
已知问题
这 不会 建议使用 bool
/int
如果你已经使用了 boolean
/integer
- 这需要修复 PHP Codesniffer。 已创建补丁,但尚未合并