-
-
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
[Php] Fix filter cache on PolyfillPackagesProvider #5390
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,12 +13,12 @@ | |||||||||||||
final class PolyfillPackagesProvider | ||||||||||||||
{ | ||||||||||||||
/** | ||||||||||||||
* @var array<PolyfillPackage::*> | ||||||||||||||
* @var null|array<int, PolyfillPackage::*> | ||||||||||||||
*/ | ||||||||||||||
private array $cachedPolyfillPackages = []; | ||||||||||||||
private null|array $cachedPolyfillPackages = null; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @return array<PolyfillPackage::*> | ||||||||||||||
* @return array<int, PolyfillPackage::*> | ||||||||||||||
*/ | ||||||||||||||
public function provide(): array | ||||||||||||||
{ | ||||||||||||||
|
@@ -27,12 +27,14 @@ public function provide(): array | |||||||||||||
return SimpleParameterProvider::provideArrayParameter(Option::POLYFILL_PACKAGES); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
$projectComposerJson = getcwd() . '/composer.json'; | ||||||||||||||
if (! file_exists($projectComposerJson)) { | ||||||||||||||
return []; | ||||||||||||||
// already cached, even only empty array | ||||||||||||||
if ($this->cachedPolyfillPackages !== null) { | ||||||||||||||
return $this->cachedPolyfillPackages; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if ($this->cachedPolyfillPackages !== []) { | ||||||||||||||
$projectComposerJson = getcwd() . '/composer.json'; | ||||||||||||||
if (! file_exists($projectComposerJson)) { | ||||||||||||||
$this->cachedPolyfillPackages = []; | ||||||||||||||
return $this->cachedPolyfillPackages; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -46,11 +48,11 @@ public function provide(): array | |||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* @param array<string, string> $require | ||||||||||||||
* @return array<PolyfillPackage::*> | ||||||||||||||
* @return array<int, PolyfillPackage::*> | ||||||||||||||
*/ | ||||||||||||||
private function filterPolyfillPackages(array $require): array | ||||||||||||||
{ | ||||||||||||||
return array_filter($require, static fn (string $packageName): bool => ! str_starts_with( | ||||||||||||||
return array_filter(array_keys($require), static fn (string $packageName): bool => str_starts_with( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here only "require": {
"symfony/polyfill-php80" => "*"
} then, filter the array('symfony/polyfill-php80') to compare with rector-src/packages/VersionBonding/PhpVersionedFilter.php Lines 32 to 37 in 6ebab94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created e2e test for it: |
||||||||||||||
$packageName, | ||||||||||||||
'symfony/polyfill-' | ||||||||||||||
)); | ||||||||||||||
|
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.
here compare no null = already cached.