From 0b8c242e1faab8b23b7ef6422717473fcfce26ef Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Mon, 31 May 2021 10:51:27 +0200 Subject: [PATCH] Fix package dependencies duplication (#472) --- src/Entity/Organization/Package.php | 27 +++++++++++++------ .../ComposerPackageSynchronizer.php | 6 ++--- templates/component/user.html.twig | 2 +- tests/Doubles/FakePackageSynchronizer.php | 4 +-- tests/MotherObject/PackageMother.php | 4 +-- .../Entity/{ => Organization}/PackageTest.php | 15 ++++++++--- 6 files changed, 39 insertions(+), 19 deletions(-) rename tests/Unit/Entity/{ => Organization}/PackageTest.php (88%) diff --git a/src/Entity/Organization/Package.php b/src/Entity/Organization/Package.php index f3280f9f..b8e320c7 100644 --- a/src/Entity/Organization/Package.php +++ b/src/Entity/Organization/Package.php @@ -170,8 +170,8 @@ public function repositoryUrl(): string } /** - * @param string[] $encounteredVersions - * @param string[] $encounteredLinks + * @param array $encounteredVersions + * @param array $encounteredLinks */ public function syncSuccess(string $name, string $description, string $latestReleasedVersion, array $encounteredVersions, array $encounteredLinks, \DateTimeImmutable $latestReleaseDate): void { @@ -179,15 +179,26 @@ public function syncSuccess(string $name, string $description, string $latestRel $this->description = $description; $this->latestReleasedVersion = $latestReleasedVersion; $this->latestReleaseDate = $latestReleaseDate; - foreach ($this->versions as $version) { - if (!in_array($version->version(), $encounteredVersions, true)) { - $this->versions->removeElement($version); + foreach ($this->versions as $key => $version) { + if (!isset($encounteredVersions[$version->version()])) { + $this->versions->remove($key); } } - foreach ($this->links as $link) { - if (!in_array($link->type().'-'.$link->target(), $encounteredLinks, true)) { - $this->links->removeElement($link); + + $uniqueLinks = []; + foreach ($this->links as $key => $link) { + $uniqueKey = $link->type().'-'.$link->target(); + if (!isset($encounteredLinks[$uniqueKey])) { + $this->links->remove($key); + continue; + } + + if (!isset($uniqueLinks[$uniqueKey])) { + $uniqueLinks[$uniqueKey] = true; + continue; } + + $this->links->remove($key); } $this->lastSyncAt = new \DateTimeImmutable(); $this->lastSyncError = null; diff --git a/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php b/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php index 9c835a7f..c3229eb5 100644 --- a/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php +++ b/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php @@ -175,7 +175,7 @@ public function synchronize(Package $package): void $link->getPrettyConstraint(), ) ); - $encounteredLinks[] = $type.'-'.$link->getTarget(); + $encounteredLinks[$type.'-'.$link->getTarget()] = true; } } } @@ -190,7 +190,7 @@ public function synchronize(Package $package): void $linkDescription, ) ); - $encounteredLinks[] = 'suggests-'.$linkName; + $encounteredLinks['suggests-'.$linkName] = true; } } @@ -205,7 +205,7 @@ public function synchronize(Package $package): void ) ); - $encounteredVersions[] = $version['prettyVersion']; + $encounteredVersions[$version['prettyVersion']] = true; } $package->syncSuccess( diff --git a/templates/component/user.html.twig b/templates/component/user.html.twig index 2c516d03..11ab70a0 100644 --- a/templates/component/user.html.twig +++ b/templates/component/user.html.twig @@ -13,7 +13,7 @@