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.

Revisions

  1. buismaarten revised this gist Dec 29, 2022. No changes.
  2. buismaarten revised this gist Dec 29, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions diff.php
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,10 @@

    class MinimalDiffOutputBuilder implements DiffOutputBuilderInterface
    {
    /**
    * @param array $diff
    * @return string
    */
    public function getDiff(array $diff): string
    {
    $result = '';
  3. buismaarten revised this gist Dec 29, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion diff.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    use SebastianBergmann\Diff\Differ;
    use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;

    final class MinimalDiffOutputBuilder implements DiffOutputBuilderInterface
    class MinimalDiffOutputBuilder implements DiffOutputBuilderInterface
    {
    public function getDiff(array $diff): string
    {
  4. buismaarten revised this gist Dec 29, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions diff.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php

    use SebastianBergmann\Diff\Differ;
    use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
  5. buismaarten created this gist Dec 29, 2022.
    27 changes: 27 additions & 0 deletions diff.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@

    use SebastianBergmann\Diff\Differ;
    use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;

    final class MinimalDiffOutputBuilder implements DiffOutputBuilderInterface
    {
    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");
    }
    }