From e8a0bb9f6fe2f45158beb99f06272ffdae360910 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 3 Aug 2022 12:41:56 +0200 Subject: [PATCH] Add Diff::rawDiffFromSebastianDiff() This eases the migration, because consumers can switch to sebastian/diff's generation logic, while preserving the legacy output format. --- .../install/files/lib/util/Diff.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wcfsetup/install/files/lib/util/Diff.class.php b/wcfsetup/install/files/lib/util/Diff.class.php index 2bae23353d..68c4384f0c 100644 --- a/wcfsetup/install/files/lib/util/Diff.class.php +++ b/wcfsetup/install/files/lib/util/Diff.class.php @@ -2,6 +2,8 @@ namespace wcf\util; +use SebastianBergmann\Diff\Differ; + /** * Diff calculates the longest common subsequence of two given * arrays and is able to generate the differences (added / removed items) @@ -333,6 +335,26 @@ class Diff return \implode("\n", $result); } + /** + * Transforms the output of sebastian/diff's Differ::diffToArray() into + * the output of self::getRawDiff(). + * + * @since 5.6 + */ + public static function rawDiffFromSebastianDiff(array $arrayDiff): array + { + return \array_map(static function ($entry) { + return [ + match($entry[1]) { + Differ::ADDED => self::ADDED, + Differ::REMOVED => self::REMOVED, + Differ::OLD => self::SAME, + }, + $entry[0], + ]; + }, $arrayDiff); + } + /** * @see Diff::getUnixDiff() */ -- 2.20.1