MediaWiki master
Wikimedia\Diff\Diff Class Reference

Class representing a 'diff' between two sequences of strings. More...

Inherited by Wikimedia\Diff\WordLevelDiff.

Collaboration diagram for Wikimedia\Diff\Diff:

Public Member Functions

 __construct ( $from_lines, $to_lines)
 Computes diff between sequences of strings.
 
 closing ()
 Get the closing set of lines.
 
 getEdits ()
 
 isEmpty ()
 Check for empty diff.
 
 lcs ()
 Compute the length of the Longest Common Subsequence (LCS).
 
 orig ()
 Get the original set of lines.
 
 reverse ()
 Compute reversed Diff.
 

Public Attributes

DiffOp[] $edits
 

Protected Attributes

int $bailoutComplexity = 0
 If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
 

Detailed Description

Class representing a 'diff' between two sequences of strings.

Stability: newable

Definition at line 34 of file Diff.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Diff\Diff::__construct ( $from_lines,
$to_lines )

Computes diff between sequences of strings.

Stability: stable
to call
Todo
Don't do work in the constructor, use a service to create diffs instead (T257472).
Parameters
string[]$from_linesAn array of strings. Typically these are lines from a file.
string[]$to_linesAn array of strings.
Exceptions
ComplexityException

Reimplemented in Wikimedia\Diff\WordLevelDiff.

Definition at line 58 of file Diff.php.

References Wikimedia\Diff\DiffEngine\setBailoutComplexity().

Member Function Documentation

◆ closing()

Wikimedia\Diff\Diff::closing ( )

Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns
string[] The sequence of strings.

Reimplemented in Wikimedia\Diff\WordLevelDiff.

Definition at line 154 of file Diff.php.

References $lines.

◆ getEdits()

Wikimedia\Diff\Diff::getEdits ( )
Returns
DiffOp[]

Definition at line 67 of file Diff.php.

References Wikimedia\Diff\Diff\$edits.

◆ isEmpty()

Wikimedia\Diff\Diff::isEmpty ( )

Check for empty diff.

Returns
bool True if two sequences were identical.

Definition at line 98 of file Diff.php.

◆ lcs()

Wikimedia\Diff\Diff::lcs ( )

Compute the length of the Longest Common Subsequence (LCS).

This is mostly for diagnostic purposed.

Returns
int The length of the LCS.

Definition at line 115 of file Diff.php.

◆ orig()

Wikimedia\Diff\Diff::orig ( )

Get the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns
string[] The original sequence of strings.

Reimplemented in Wikimedia\Diff\WordLevelDiff.

Definition at line 134 of file Diff.php.

References $lines.

◆ reverse()

Wikimedia\Diff\Diff::reverse ( )

Compute reversed Diff.

SYNOPSIS:

$diff = new Diff($lines1, $lines2); $rev = $diff->reverse();

Returns
self A Diff object representing the inverse of the original diff.

Definition at line 82 of file Diff.php.

Member Data Documentation

◆ $bailoutComplexity

int Wikimedia\Diff\Diff::$bailoutComplexity = 0
protected

If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.

Definition at line 45 of file Diff.php.

◆ $edits

DiffOp [] Wikimedia\Diff\Diff::$edits

Definition at line 39 of file Diff.php.

Referenced by Wikimedia\Diff\Diff\getEdits().


The documentation for this class was generated from the following file: