rector: Vendor classes in PHPDoc are not prefixed by `RectorPrefix...`, making PHPStan fails

Hi! 👋

Bug Report

Subject Details
Rector version 0.11.42

Minimal PHP Code Causing Issue

That’s not reproducible on https://getrector.org/demo.

When creating a custom Rector by extending AbstractRector, using $this->parameterProvider->... to retrieve a parameter makes PHPStan fails because it does not know about \Symplify\PackageBuilder\Parameter\ParameterProvider class.

Indeed, this vendor class is prefixed by RectorPrefix20210804 (see https://github.com/rectorphp/rector/blob/main/src/Rector/AbstractRector.php#L48) but is not when used in the phpdoc: https://github.com/rectorphp/rector/blob/main/src/Rector/AbstractRector.php#L78-L81: image

The same issue applies to other vendor classes like Symfony\Component\Console\Style\SymfonyStyle, Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser or Symplify\Skipper\Skipper\Skipper.

Expected Behaviour

The @var annotation should see its type prefixed by RectorPrefix20210804 too.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Hi!

Yes I think I can provide a patch for that, a big thank you for the guidelines, that’s much appreciated! 😃

I will give it a try this week-end, thanks!

Closing as reverted to working state. The issue is in php-scoper itself, it should be fixed to avoid these per-project patches.

Thank you for the effort and exploration 👍

Yes, please see #739

Yeah, I think it would be better to write a fix for php-scoper, there is already an issue opened for phpdoc support https://github.com/humbug/php-scoper/issues/462

I’ve just created https://github.com/Kocal/rector-6614, thanks!

I assume “AddRoutesToPages” is Rector rule without “Rector” suffix that you try to analyze?

Yep! I’m gonna rename it 😃

@Kocal could you provide patch for it? The code need to be added possibly can duplicate the following lines:

https://github.com/rectorphp/rector-src/blob/1f538c68717d8f04896c6c7a17ff9f761f230612/scoper.php#L105-L109

and update to Symplify\PackageBuilder\Parameter\ParameterProvider in next line. Then next process:

  • run sh ./full_build.sh
  • swith to your project, remove vendor/rector/rector content except preload.php and bootstrap.php.
  • copy generated rector-prefixed-downgraded inside rector-src’s dir content into your project’s vendor/rector/rector
  • re-run your custom rector.

If everything is ok, you can remove rector-prefixed-downgraded directory, then commit the updated scoper.php then send PR