-
-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DX] Add "Related polyfill" feature to upgrade based on used symfony/polyfill-* packages #5388
Conversation
c9105b7
to
7b8b0bd
Compare
Let's ship it to test first 2 rules in the wild 👍 |
|
||
$rectorConfig->phpVersion(PhpVersion::PHP_74); | ||
|
||
$rectorConfig->polyfillPackages([PolyfillPackage::PHP_80]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs test if rectorConfig->polyfillPackages()
is not enabled, to verify it skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a PR to add test for it:
@@ -25,6 +28,15 @@ public function filter(iterable $rectors): array | |||
|
|||
$activeRectors = []; | |||
foreach ($rectors as $rector) { | |||
if ($rector instanceof RelatedPolyfillInterface) { | |||
$polyfillPackageNames = $this->polyfillPackagesProvider->provide(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be moved before loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, init before loop:
$polyfillPackageNames = null;
and use coalesce on loop:
$polyfillPackageNames ??= this->polyfillPackagesProvider->provide();
That cache is then no longer needed, as cached on loop itself to use isset data when available.
/** | ||
* @var array<PolyfillPackage::*> | ||
*/ | ||
private array $cachedPolyfillPackages = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be nullable,
- cache is null: never filled
- cache is array, it filled, even empty, it means already read composer.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, could you add it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []; | ||
} | ||
|
||
if ($this->cachedPolyfillPackages !== []) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should compare to null
} | ||
|
||
$projectComposerJson = getcwd() . '/composer.json'; | ||
if (! file_exists($projectComposerJson)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file exists can be verified after null check cache on unitialized verify
Closes rectorphp/rector#8368