[DX] Add "Related polyfill" feature to upgrade based on used symfony/polyfill-* packages#5388
[DX] Add "Related polyfill" feature to upgrade based on used symfony/polyfill-* packages#5388TomasVotruba merged 2 commits intomainfrom
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.
It needs test if rectorConfig->polyfillPackages() is not enabled, to verify it skipped
There was a problem hiding this comment.
I created a PR to add test for it:
| $activeRectors = []; | ||
| foreach ($rectors as $rector) { | ||
| if ($rector instanceof RelatedPolyfillInterface) { | ||
| $polyfillPackageNames = $this->polyfillPackagesProvider->provide(); |
There was a problem hiding this comment.
this can be moved before loop
There was a problem hiding this comment.
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.
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.
Makes sense, could you add it?
There was a problem hiding this comment.
| return []; | ||
| } | ||
|
|
||
| if ($this->cachedPolyfillPackages !== []) { |
| } | ||
|
|
||
| $projectComposerJson = getcwd() . '/composer.json'; | ||
| if (! file_exists($projectComposerJson)) { |
There was a problem hiding this comment.
file exists can be verified after null check cache on unitialized verify
rules-tests/CodeQuality/Rector/Ternary/SimplifyTautologyTernaryRector/Fixture/fixture.php
Show resolved
Hide resolved
| $composerContents = FileSystem::read($projectComposerJson); | ||
| $composerJson = Json::decode($composerContents, Json::FORCE_ARRAY); | ||
|
|
||
| $this->cachedPolyfillPackages = $this->filterPolyfillPackages($composerJson['require'] ?? []); |
There was a problem hiding this comment.
this fallback to empty array means the cache never works on no polifill found, that means composer.json will be re-read, that's why nullable for init value comparison is needed instead of compare to non-empty array
Closes rectorphp/rector#8368