Created
October 14, 2017 11:25
-
-
Save jk/4d430ee501ddfa84524ce6cb0f3abbee to your computer and use it in GitHub Desktop.
Diff Composer Packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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