PhpStorm - есть ли способ преобразовать PHPDoc в подсказку типа и вернуть объявление типа? - PullRequest
1 голос
/ 23 октября 2019

Есть ли в 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: похоже, ваш пост в основном кодовый;пожалуйста, добавьте больше деталей.

1 Ответ

1 голос
/ 23 октября 2019

Попробуйте 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...