Rector: TypedPropertyRector does not remove docblocks

Created on 29 Nov 2019  Â·  16Comments  Â·  Source: rectorphp/rector

rector.yaml:

parameters:
    php_version_features: '7.4'

services:
    Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector: ~
    Rector\Php74\Rector\Property\TypedPropertyRector: ~
    /** @var string */
    public $name;

becomes

    /** @var string */
    public string $name;

I expect it to be

    public string $name;

All 16 comments

It also doesn't work using the example in https://www.tomasvotruba.cz/blog/2018/11/15/how-to-get-php-74-typed-properties-to-your-code-in-few-seconds/

vendor/bin/rector process <path> --set php74 --dry-run

Rector rule doesn't touch any docs.

It's better to use no_superfluous_phpdoc_tags that handle this better

In that case you should update the docs and your blog post

Screen Shot 2019-11-30 at 09 39 02

Yup, removing the useless docblocks is what you really want to do when updating to 7.4. The blogpost should describe how to do that. Now it just claims that it works that way which is not the case.

Agreed. Could you send PR to fix this expectation?

Also, the type is not determined only from doc block. More type inference is used

Too busy with other things sadly. 😞

No troubles :+1:

@TomasVotruba I believe the PR I created should address this as you requested.

Thanks

no_superfluous_phpdoc_tags does not support this.

Honestly Rector should support it… you even listed it in your blog post because it's the logical thing to do. Maybe a separate rector? I more than willing to submit a PR if you're open for it.

no_superfluous_phpdoc_tags does not support this.

Not yet, it will be in the scope as it was for the return/param types

I more than willing to submit a PR if you're open for it.

If you're up for it, I'd be happy to merge :+1:

I'll look at it this week

Is there a work around to get the docblocks to be automatically removed?

There is fixer in PHP cs fixer that handles param types removal.
I expect similar rule for property types

Created a PR to add this to PHP-CS-Fixer, would love to get a review :) https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4713

I get more and more feature requests for this. Let's give it a try then

Was this page helpful?
0 / 5 - 0 ratings