PhpStorm — есть ли способ преобразовать PHPDoc в подсказку типа и вернуть объявление типа?

Есть ли в 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;
}

...to

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

    return $this;
}

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

Filltext: Похоже, ваш пост в основном состоит из кода; пожалуйста, добавьте некоторые подробности.


person goulashsoup    schedule 23.10.2019    source источник
comment
Для этого могут быть лучшие инструменты, такие как Rector.   -  person Nico Haase    schedule 23.10.2019


Ответы (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;
}
person Dry7    schedule 23.10.2019