Skip to content
Snippets Groups Projects

Issue #3261847: Add helpful methods to compute the difference between two ComposerUtility objects

Merged Issue #3261847: Add helpful methods to compute the difference between two ComposerUtility objects
@@ -157,33 +157,29 @@ class ComposerUtility {
/**
* Returns the packages added in another directory.
*
* @param self $other
* @param self $that
* A Composer utility wrapper around a different directory.
*
* @return \Composer\Package\PackageInterface[]
* The packages that were added in the other directory, keyed by name.
*/
public function getPackagesAddedBy(self $other): array {
return array_diff_key(
$other->getInstalledPackages(),
$this->getInstalledPackages()
);
public function getPackagesAddedBy(self $that): array {
// Return the packages that are there, but not here.
return array_diff_key($that->getInstalledPackages(), $this->getInstalledPackages());
}
/**
* Returns the packages that were removed in another directory.
*
* @param self $other
* @param self $that
* A Composer utility wrapper around a different directory.
*
* @return \Composer\Package\PackageInterface[]
* The packages that were removed in the other directory, keyed by name.
*/
public function getPackagesRemovedBy(self $other): array {
return array_diff_key(
$this->getInstalledPackages(),
$other->getInstalledPackages()
);
public function getPackagesRemovedBy(self $that): array {
// Return the packages that are here, but not there.
return array_diff_key($this->getInstalledPackages(), $that->getInstalledPackages());
}
/**
@@ -192,19 +188,18 @@ class ComposerUtility {
* A package will be considered "updated" if its version in the other
* directory has changed *at all*.
*
* @param self $other
* @param self $that
* A Composer utility wrapper around a different directory.
*
* @return \Composer\Package\PackageInterface[]
* The packages in the current directory that were updated in the other
* directory, keyed by name.
*/
public function getPackagesUpdatedBy(self $other): array {
$mine = $this->getInstalledPackages();
$theirs = $other->getInstalledPackages();
public function getPackagesUpdatedBy(self $that): array {
$theirs = $that->getInstalledPackages();
// Only compare packages that are installed in both places.
$packages = array_intersect_key($mine, $theirs);
// Only compare packages that are both here and there.
$packages = array_intersect_key($this->getInstalledPackages(), $theirs);
$filter = function (PackageInterface $package, string $name) use ($theirs): bool {
return Comparator::notEqualTo($package->getVersion(), $theirs[$name]->getVersion());
Loading