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
All threads resolved!
All threads resolved!
Files
9
@@ -155,52 +155,37 @@ class ComposerUtility {
}
/**
* Returns the packages added in another directory.
* Returns the packages that are in the current project, but not in another.
*
* @param self $other
* A Composer utility wrapper around a different directory.
*
* @return \Composer\Package\PackageInterface[]
* The packages that were added in the other directory, keyed by name.
* The packages which are installed in the current project, but not in the
* other one, keyed by name.
*/
public function getPackagesAddedBy(self $other): array {
return array_diff_key(
$other->getInstalledPackages(),
$this->getInstalledPackages()
);
public function getPackagesNotIn(self $other): array {
return array_diff_key($this->getInstalledPackages(), $other->getInstalledPackages());
}
/**
* Returns the packages that were removed in another directory.
* Returns the packages which have a different version in another project.
*
* @param self $other
* 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()
);
}
/**
* Returns the packages that were updated in another directory.
* This compares the current project with another one, and returns packages
* which are present in both, but in different versions.
*
* @param self $other
* 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.
* The packages which are present in both the current project and the other
* one, but in different versions, keyed by name.
*/
public function getPackagesUpdatedBy(self $other): array {
$mine = $this->getInstalledPackages();
public function getPackagesWithDifferentVersionsIn(self $other): array {
$theirs = $other->getInstalledPackages();
$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