dunglas/phpdoc-to-typehint

此包已被废弃,不再维护。没有建议的替代包。

从 PHPDoc 注释生成标量类型提示

安装: 72

依赖: 0

建议者: 0

安全: 0

星标: 230

关注者: 12

分支: 17

开放问题: 0

类型:项目

v0.1.0 2016-05-15 11:12 UTC

This package is auto-updated.

Last update: 2021-01-28 22:40:29 UTC


README

已归档! 此存储库已归档。建议使用 PHP CS Fixer(尤其是 phpdoc_to_param_typephpdoc_to_return_type 规则)或 Rector

phpdoc-to-typehint 会自动将标量类型提示和返回类型添加到 PHP 项目的所有函数和方法中,使用现有的 PHPDoc 注释。

Build Status

警告: 此项目处于早期开发阶段。它 可能会损坏 您的代码。在运行此命令之前,请确保备份您的代码,并在运行后运行测试套件。

报告 使用此工具发现的任何错误。

安装和用法

  1. 下载最新的 PHAR 文件
  2. 运行 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 赞助。