PhpStorm-有没有一种方法可以将PHPDoc转换为类型提示并返回类型声明?

问题描述 投票:1回答:1

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

例如转换...

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

    return $this;
}

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

...到

public function setCoefficient(float $coefficient): self
{
    $this->coefficient = (float) $coefficient;

    return $this;
}

public function getCoefficient(): float
{
    return $this->coefficient;
}

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

php phpstorm php-7 type-hinting type-declaration
1个回答
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;
}
© www.soinside.com 2019 - 2024. All rights reserved.