Subscribe to PHP Freaks RSS

Tomas Votruba: How to Complete Type Declarations without Docblocks with Rector

syndicated from www.phpdeveloper.org on January 7, 2019

Following up on his prior post showing how to convert DocBlock comments to official type hinting, Tomas Votruba has continued the series with a new post showing how to do the same thing but without previously defined DocBlocks.

In previous post we looked at how to migrate from docblocks to type declarations. From @param Type $param to Type $param. Even if it doesn't break code like coding standards do, works with inheritance, localized self and static and propagates types to all child classes, it's still not such a big deal.

But how do you complete type declarations if don't have any docblocks?

After a "gloom and doom" start to the post, he circles back around and shows how PHPStan and Reactor can help with static analysis. After providing several examples of how the refactor should look, he shows how to set up Reactor for both return types and the migration of properties to their correctly typed versions automatically.