MMOframework
Why AI Playground Libraries Documentation Search Agency
FR EN
Index

DiffFile

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

class

DiffFile

DiffFile.php:15

One file of a Diff: its paths and modes on each side, its blobs, and the hunks of what changed.

class MMO\git\helpers\DiffFile implements JsonSerializable
Namespace
MMO\git\helpers
Implements
JsonSerializable
A new file has no old path, a deleted one no new path. A binary file, a pure rename or a mode change has no hunk.
foreach ($repo->diff('v3.0.1', 'develop') as $file) { echo $file->status, ' ', $file->path(), ' +', $file->additions(), ' -', $file->deletions(), "\n"; }

Index

ADDED
COPIED
DELETED
MODIFIED
RENAMED
SUBMODULE_MODEthe mode git gives a submodule: its "content" is the commit it points to
binary
hunks
newBlob
newMode
newPath
oldBlob
oldMode
oldPath
similarity
status
additions()
deletions()
finish()Settle what the header left open, once the file is read.
FromHeader($paths) staticStart a file from the rest of its diff --git a/<old> b/<new> line.
HeaderPath($path) static
isSubmodule()
jsonSerialize()
modeChanged()
parseHeader($line)Read one of the lines between diff --git and the first hunk.
path()
StripPrefix($path, $prefix) static
Unquote($quoted, $end) staticA path as git writes it: as it is, or between double quotes with C escapes (\", \t, \303\251) when it holds a quote, a backslash or a control character.

Constants6

ADDED

const ADDED = 'added'

COPIED

const COPIED = 'copied'

DELETED

const DELETED = 'deleted'

MODIFIED

const MODIFIED = 'modified'

RENAMED

const RENAMED = 'renamed'

SUBMODULE_MODE

the mode git gives a submodule: its "content" is the commit it points to

const SUBMODULE_MODE = '160000'

Properties10

binary

bool $binary = false
Type
bool

hunks

array $hunks = []
Type
array

similarity

?int $similarity = null
Type
null | int

Methods12

finish()

DiffFile.php:148

Settle what the header left open, once the file is read.

function finish(): void
returnsvoid

FromHeader($paths)

staticDiffFile.php:51

Start a file from the rest of its diff --git a/<old> b/<new> line.

static function FromHeader(string $paths): selfThe two paths are only a guess there when they hold spaces: the `---`/`+++` and `rename` lines that follow settle them, and only a binary file or a mode change has none of those.
$pathsstringwhat follows diff --git
returnsself

HeaderPath($path)

staticDiffFile.php:143
protected static function HeaderPath(string $path): string
$pathstring
returnsstringthe path of a ---/+++ line, which git ends with a tab when it holds a space

isSubmodule()

DiffFile.php:165
function isSubmodule(): bool
returnsboola submodule, whose lines are the commits it points to

modeChanged()

DiffFile.php:160
function modeChanged(): bool
returnsboolits mode changed (made executable, ...)

parseHeader($line)

DiffFile.php:108

Read one of the lines between diff --git and the first hunk.

function parseHeader(string $line): void
$linestring
returnsvoid

StripPrefix($path, $prefix)

staticDiffFile.php:99
protected static function StripPrefix(string $path, string $prefix): ?string
$pathstring
$prefixstring
returnsnull | string$path without git's a//b/ prefix; null for /dev/null, the side that does not exist

Unquote($quoted, $end)

staticDiffFile.php:84

A path as git writes it: as it is, or between double quotes with C escapes (\", \t, \303\251) when it holds a quote, a backslash or a control character.

static function Unquote(string $quoted, int &$end = 0): string
$quotedstringstarting with the opening quote
$end = 0intreceives the offset just after the closing quote
returnsstring