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:
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
- Updated Rector to commit 877cbb2de8150b672a966d7a8907ed63769e1cdd https://github.com/rectorphp/rector-src/commit/877cbb2de8150b672a966d7a8907ed63769e1cdd fix(scoper): prefix vendor classes from PHPDo... — committed to rectorphp/rector by TomasVotruba 3 years ago
- fix(scoper): prefix vendor classes from PHPDoc, close #6614 (#739) — committed to echo511/rector by Kocal 3 years ago
- Revert "fix(scoper): prefix vendor classes from PHPDoc, close #6614 (#739)" (#740) This reverts commit 877cbb2de8150b672a966d7a8907ed63769e1cdd. — committed to echo511/rector by samsonasik 3 years ago
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!
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:vendor/rector/rector
content exceptpreload.php
andbootstrap.php
.rector-prefixed-downgraded
insiderector-src
’s dir content into your project’svendor/rector/rector
If everything is ok, you can remove
rector-prefixed-downgraded
directory, then commit the updated scoper.php then send PR