Skip to content

Instantly share code, notes, and snippets.

@jk
Created October 14, 2017 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jk/4d430ee501ddfa84524ce6cb0f3abbee to your computer and use it in GitHub Desktop.
Save jk/4d430ee501ddfa84524ce6cb0f3abbee to your computer and use it in GitHub Desktop.
Diff Composer Packages
<?php
$old = [
'muz' => [
'package1' => [
'1.0.0',
'1.0.1',
'2.0.0'
],
'package2' => ['1.0.0'],
'package3' => ['1.0.0', '2.0.0']
],
'notchanged' => [
'otherPackage1' => ['1.0.0']
],
'changed' => [
'anotherPackage1' => ['1.0.0']
]
];
$new = [
'muz' => [
'package1' => [
'1.0.0',
'2.0.0',
'2.0.1'
],
'package3' => ['1.0.0', '2.0.0'],
'package4' => ['1.0.0']
],
'notchanged' => [
'otherPackage1' => ['1.0.0']
],
'changed' => [
'anotherPackage1' => ['1.0.0', '1.0.1'],
'anotherPackage2' => ['1.0.0']
]
];
$old_flat = [];
foreach ($old as $vendor => $packages) {
foreach ($packages as $package => $versions) {
foreach ($versions as $version) {
$old_flat[] = $vendor. '/' . $package . ':' . $version;
}
}
}
$new_flat = [];
foreach ($new as $vendor => $packages) {
foreach ($packages as $package => $versions) {
foreach ($versions as $version) {
$new_flat[] = $vendor. '/' . $package . ':' . $version;
}
}
}
// array_diff
$not_changed = array_intersect($old_flat, $new_flat);
$removed = array_filter($old_flat, function ($package) use ($not_changed) {
return !in_array($package, $not_changed);
});
$added = array_filter($new_flat, function ($package) use ($not_changed) {
return !in_array($package, $not_changed);
});
sort($added);
sort($removed);
echo "# Added\n";
foreach ($added as $item) {
echo "* $item\n";
}
echo "\n";
echo "# Removed\n";
foreach ($removed as $item) {
echo "* $item\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment