phpspec/php-diff
phpspec/php-diff is a lightweight PHP library for generating diffs between strings and arrays. It computes insertions, deletions, and changes and can render readable output via formatters, making it useful for tests, code review tooling, and text comparison.
composer require phpspec/php-diffuse Diff\Diff;
use Diff\Renderer\Text\Unified;
$diff = new Diff('old line', 'new line');
$renderer = new Unified();
echo $renderer->render($diff); // Outputs unified diff format
Unified or Inline renderers to display changes in command-line utilities (e.g., config migration scripts, deployment hooks).$this->assertSame($expected, $actual, $renderer->render(new Diff($expected, $actual)));
Html\Inline) to visualize diffs in admin panels or code review UIs (often used with assets like Codeception or custom tools).Diff\Differ::diff($from, $to, $options)).Renderer\RendererInterface to build tailored outputs (e.g., JSON diffs for APIs, colorized terminal output).ignoreWhitespace in Differ options to avoid noise:
$differ = new Differ(['ignoreWhitespace' => true]);
$diff = $differ->diff($old, $new);
Unified with constructor arg to control contextSize (default: 3 lines).Diff\Renderer\{Text|Html}; Text includes Unified, Inline, OldStyle; Html provides inline annotated HTML.How can I help you explore Laravel packages today?