MMOframework
Why AI Playground Libraries Documentation Search Agency
FR EN
Index

Diff

MMO\git\helpers · 1 symbol · generated 27 Oct 2026

class

Diff

Diff.php:20

What changed between two revisions, as git diff says it: one DiffFile per file, each with its

class MMO\git\helpers\Diff implements JsonSerializable, IteratorAggregate, Countable
Namespace
MMO\git\helpers
Implements
JsonSerializable, IteratorAggregate, Countable
See
DiffHunk of DiffLine. Made by Repository::diff and Repository::diffCommit, or by Parse from any git diff output.
It serializes to JSON as it is: `{from, to, additions, deletions, files: [...]}`.
$diff = $repo->diff('v3.0.1', 'develop'); echo count($diff), ' files, +', $diff->additions(), ' -', $diff->deletions(), "\n"; foreach ($diff->getFile('src/Git.php')?->hunks ?? [] as $hunk) { foreach ($hunk->lines as $line) {echo $line->type, $line->text, "\n";} }

Index

files
from readonly
to readonly
additions()
count()
deletions()
getFile($path)
getIterator()
jsonSerialize()
Parse($output, $from, $to) staticRead the output of git diff (a patch, in git's own format -- not --color, not --word-diff).
__construct($from, $to)

Properties3

files

array $files = []
Type
array

from

readonly
readonly ?string $from
Type
null | string

Methods8

additions()

Diff.php:74
function additions(): int
returnsinthow many lines are added, all files together

deletions()

Diff.php:79
function deletions(): int
returnsinthow many lines are removed, all files together

getFile($path)

Diff.php:67
function getFile(string $path): ?MMO\git\helpers\DiffFile
$pathstringa path from the repository's root, new or old
returnsnull | DiffFilethe file at $path, on the new side first

Parse($output, $from, $to)

staticDiff.php:40

Read the output of git diff (a patch, in git's own format -- not --color, not --word-diff).

static function Parse(string $output, ?string $from = null, ?string $to = null): selfPaths are read as git writes them with its default `a/` and `b/` prefixes; [`Repository::diff`](https://mmoframework.fr/en/documentation/mmo.git/php/helpers/Repository.md#repository-diff) asks for those whatever the configuration says.
$outputstring
$from = nullnull | string$from
$to = nullnull | string$to
returnsself

__construct($from, $to)

Diff.php:28
function __construct(?string $from = null, ?string $to = null)
$from = nullnull | stringthe old revision
$to = nullnull | stringthe new revision; null: the working tree