GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - php-forge/diff: Git-compatible line diff for PHP: a port of Git's xdiff Myers pipeline with the indent heuristic and a unified diff renderer.

BranchesTags
Open more actions menu

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
.agents/skills
.agents/skills
 
 
.claude/skills
.claude/skills
 
 
.github
.github
 
 
docs
docs
 
 
runtime
runtime
 
 
skills/php-forge-diff
skills/php-forge-diff
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.json
.prettierrc.json
 
 
.styleci.yml
.styleci.yml
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer-require-checker.json
composer-require-checker.json
 
 
composer.json
composer.json
 
 
ecs.php
ecs.php
 
 
infection.json5
infection.json5
 
 
llms.txt
llms.txt
 
 
phpstan.neon
phpstan.neon
 
 
rector.php
rector.php
 
 
testo.php
testo.php
 
 

Repository files navigation

PHP Forge

Diff


Testo Mutation Testing PHPStan Security

Git-compatible line diff for PHP
A port of Git's default diff, indent heuristic included, plus a unified diff renderer, with no runtime dependencies.

Features

Feature Overview

Installation

composer require php-forge/diff:^0.1

Quick start

LineDiffer implements PHPForge\Diff\DifferInterface. diff() splits both strings on "\n" and returns an ordered list of DiffLine objects, each tagged with a DiffOp:

  • DiffOp::Remove: the line exists only in $old.
  • DiffOp::Add: the line exists only in $new.
  • DiffOp::Context: the line exists on both sides.

Every input line appears exactly once, so dropping the Add lines reconstructs $old and dropping the Remove lines reconstructs $new.

use PHPForge\Diff\{DiffOp, LineDiffer};

$old = "apple\nbanana\ncherry";
$new = "apple\nblueberry\ncherry";

foreach ((new LineDiffer())->diff($old, $new) as $line) {
    echo match ($line->op) {
        DiffOp::Context => ' ',
        DiffOp::Remove => '-',
        DiffOp::Add => '+',
    } . $line->line . "\n";
}
 apple
-banana
+blueberry
 cherry

UnifiedDiffRenderer turns two texts into a unified diff in Git's format, hunk headers and function context included, without the diff --git and index lines.

use PHPForge\Diff\UnifiedDiffRenderer;

$old = "apple\nbanana\ncherry\n";
$new = "apple\nblueberry\ncherry\n";

echo (new UnifiedDiffRenderer())->render($old, $new, 'a/fruit.txt', 'b/fruit.txt');
--- a/fruit.txt
+++ b/fruit.txt
@@ -1,3 +1,3 @@
 apple
-banana
+blueberry
 cherry

What you get

Class Result Cost
LineDiffer The edit script of git diff with its default settings O((N + M) ยท D) time, linear memory
UnifiedDiffRenderer The text of git diff --unified=<n> from the --- line on The injected differ plus one pass over edits

N and M are the line counts of $old and $new, and D is the edit distance. Like Git, LineDiffer favours readable scripts over the shortest one, so its edit count is not always minimal. Unlike Git, it has no cost limit, so on very expensive inputs its script can differ from Git's. See the algorithms guide for the pipeline and its trade-offs.

Documentation

  • ๐Ÿ“š Installation guide
  • ๐Ÿงฎ Algorithms guide
  • ๐Ÿ’ก Usage examples
  • ๐Ÿงช Testing guide
  • ๐Ÿค– AI assistance

AI assistance

AI agents: read the documentation index and fetch the Markdown version of a page by appending index.md to its URL. The AI agents guide covers skill installation, client setup and verification.

  • ๐Ÿค– php-forge-diff skill: Line edit scripts and unified diffs.

If hosted documentation does not match the installed revision or is unavailable, use the repository guides, the skill source, the source PHPDoc and the changelog.

Package information

PHP Latest Stable Version Total Downloads

Project status

Codecov PHPStan Level Max Quality

Built with AI

Built with Claude Code Built with Codex Reviewed by CodeRabbit

Our social networks

Follow on X Follow on Facebook

License

License

About

Git-compatible line diff for PHP: a port of Git's xdiff Myers pipeline with the indent heuristic and a unified diff renderer.

Topics

diffgitline-diffmyersphpphp-forgeunified-diffxdiff

Resources

Readme
License

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

Generated from yii2-extensions/template
You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.