PhpStorm-是否可以将PHPDoc转换为类型提示并返回类型声明?

时间:2019-10-23 07:35:35

标签: php phpstorm php-7 type-hinting type-declaration

PhpStorm中是否可以将PHPDoc转换为类型提示并返回类型声明?

例如转换...

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");

$result=array_diff($a1,$a2);
print_r($result);

...到

/**
 * @param float $coefficient
 * @return $this
 */
public function setCoefficient($coefficient)
{
    $this->coefficient = (float) $coefficient;

    return $this;
}

/**
 * @return float
 */
public function getCoefficient()
{
    return $this->coefficient;
}

Filltext:您的帖子似乎大部分是代码;请添加更多详细信息。

1 个答案:

答案 0 :(得分:1)

尝试https://github.com/dunglas/phpdoc-to-typehint

之前:

<?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;
}