dunglas / phpdoc-to-typehint
此包已被废弃,不再维护。没有建议的替代包。
从 PHPDoc 注释生成标量类型提示
v0.1.0
2016-05-15 11:12 UTC
Requires
- php: >=7.0.0
- ext-tokenizer: *
- phpdocumentor/reflection: ^2.0@dev
- phpdocumentor/reflection-common: ^1.0@dev
- phpdocumentor/reflection-docblock: ^3.0@dev
- sebastian/diff: ^1.3
- symfony/console: ^2.7.0
- symfony/finder: ^2.7.0
This package is auto-updated.
Last update: 2021-01-28 22:40:29 UTC
README
已归档! 此存储库已归档。建议使用 PHP CS Fixer(尤其是 phpdoc_to_param_type
和 phpdoc_to_return_type
规则)或 Rector。
phpdoc-to-typehint
会自动将标量类型提示和返回类型添加到 PHP 项目的所有函数和方法中,使用现有的 PHPDoc 注释。
警告: 此项目处于早期开发阶段。它 可能会损坏 您的代码。在运行此命令之前,请确保备份您的代码,并在运行后运行测试套件。
请 报告 使用此工具发现的任何错误。
安装和用法
- 下载最新的 PHAR 文件
- 运行
php phpdoc-to-typehint.phar <your-project-directory>
您的项目应该具有标量类型提示和返回类型声明。
之前
<?php /** * @param int|null $a * @param string $b * * @return float */ function bar($a, $b, bool $c, callable $d = null) { return 0.0; }
之后
<?php /** * @param int|null $a * @param string $b * * @return float */ function bar(int $a = null, string $b, bool $c, callable $d = null) : float { return 0.0; }
功能
支持
- 函数
- 类和特质的方法
- 接口中的方法定义
- PHPDoc 继承
- PHP 7.1 可空类型(可以使用
--no-nullable-types
选项禁用)
致谢
由 Kévin Dunglas 创建。由 Les-Tilleuls.coop 赞助。