Skip to content

Instantly share code, notes, and snippets.

@buismaarten
Last active December 29, 2022 13:52
Show Gist options
  • Select an option

  • Save buismaarten/161be1b43601e0042a4e75ca1366a94a to your computer and use it in GitHub Desktop.

Select an option

Save buismaarten/161be1b43601e0042a4e75ca1366a94a to your computer and use it in GitHub Desktop.
<?php
use SebastianBergmann\Diff\Differ;
use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
class MinimalDiffOutputBuilder implements DiffOutputBuilderInterface
{
/**
* @param array $diff
* @return string
*/
public function getDiff(array $diff): string
{
$result = '';
foreach ($diff as $entry) {
$flag = '';
if ($entry[1] === Differ::ADDED) {
$flag = '+';
}
if ($entry[1] === Differ::REMOVED) {
$flag = '-';
}
$result .= sprintf(" %-1s %s\n", $flag, rtrim($entry[0]));
}
return rtrim($result, "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment