\Drupal\strata\Diff DiffHunk

One run of lines that a diff says are the same, added, removed or changed.

Structured rather than a formatted string, because the operator-facing table needs a class per line and a formatted diff would have to be parsed back to get one. Core's DiffFormatter produces classic diff text, which is the right output for a patch and the wrong one for a table with two columns.

Line numbers are 1-based and are the numbers in the value the lines came from, so a hunk deep in a long field reports where it is rather than where it is in the hunk.

Summary

Methods
Properties
Constants
__construct
isChange
height
jsonSerialize
type
before
after
beforeLine
afterLine
COPY
ADD
DELETE
CHANGE
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

COPY

COPY = 'copy'

Lines present in both values.

ADD

ADD = 'add'

Lines only in the later value.

DELETE

DELETE = 'delete'

Lines only in the earlier value.

CHANGE

CHANGE = 'change'

Lines that differ between the two values.

Properties

$type

$type : string

Type

string

$before

$before : array

Type

array<string|int, mixed>

$after

$after : array

Type

array<string|int, mixed>

$beforeLine

$beforeLine : int

Type

int

$afterLine

$afterLine : int

Type

int

Methods

__construct()

__construct(string  $type, list  $before = [], list  $after = [], int  $beforeLine = 0, int  $afterLine = 0) : mixed

Constructs a hunk.

Parameters

string $type

One of COPY, ADD, DELETE or CHANGE.

list $before

Lines as they were.

list $after

Lines as they became.

int $beforeLine

The line the earlier run starts at, counting from one.

int $afterLine

The line the later run starts at, counting from one.

Returns

mixed —

isChange()

isChange() : bool

Whether this hunk represents a difference.

Returns

bool —

FALSE for a copied run.

height()

height() : int

How many lines the hunk covers.

Returns

int —

The larger of the two runs.

jsonSerialize()

jsonSerialize() : array

{@inheritdoc}

Returns

array —