Search code examples
phpstormphpstorm-2018.1

Automatically adding return types to methods and functions


Is there an option to automatically add return types, or at least all me to generate them?

What I want is my methods before PhpStorm generates the return types:

function isValid() 
{
    return true;
}

After

function isValid(): bool
{
    return true;
}

Is this possible?


Solution

  • This issue was already answered at: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000163824-Automatically-add-return-type-declarations-

    By someone whose profile picture looks like that of LazyOne. ;-)

    Their answer (quoted and link added) is:

    ... If you are talking about adding ": QueryBuilder" declaration for PHP 7.x -- the "Php Inspections (EA Extended)" plugin has such intentions/quick fixes; not sure if PhpStorm has the same/similar out of the box.