Differ
in package
Diff implementation.
Table of Contents
- $header : string
- $showNonDiffLines : bool
- __construct() : mixed
- diff() : string
- Returns the diff between two arrays or strings as string.
- diffToArray() : array<string|int, mixed>
- Returns the diff between two arrays or strings as array.
- calculateEstimatedFootprint() : int|float
- Calculates the estimated memory footprint for the DP-based method.
- checkIfDiffInOld() : array<string|int, mixed>
- Takes input of the diff array and returns the old array.
- detectUnmatchedLineEndings() : bool
- Returns true if line ends don't match on fromMatches and toMatches.
- getArrayDiffParted() : array<string|int, mixed>
- getBuffer() : string
- Generates buffer in string format, returning the patch.
- getDiffBufferElement() : string
- Gets individual buffer element.
- getDiffBufferElementNew() : string
- Gets individual buffer element with opening.
- getNewLineMatches() : array<string|int, mixed>
- Get new strings denoting new lines from a given string.
- selectLcsImplementation() : LongestCommonSubsequence
- splitStringByLines() : array<string|int, mixed>
- Checks if input is string, if so it will split it line-by-line.
- validateDiffInput() : string
- Casts variable to string if it is not a string or array.
Properties
$header
private
string
$header
$showNonDiffLines
private
bool
$showNonDiffLines
Methods
__construct()
public
__construct([string $header = "--- Original
+++ New
" ][, bool $showNonDiffLines = true ]) : mixed
Parameters
- $header : string = "--- Original +++ New "
- $showNonDiffLines : bool = true
Return values
mixed —diff()
Returns the diff between two arrays or strings as string.
public
diff(array<string|int, mixed>|string $from, array<string|int, mixed>|string $to[, LongestCommonSubsequence $lcs = null ]) : string
Parameters
- $from : array<string|int, mixed>|string
- $to : array<string|int, mixed>|string
- $lcs : LongestCommonSubsequence = null
Return values
string —diffToArray()
Returns the diff between two arrays or strings as array.
public
diffToArray(array<string|int, mixed>|string $from, array<string|int, mixed>|string $to[, LongestCommonSubsequence $lcs = null ]) : array<string|int, mixed>
Each array element contains two elements:
-
[0] => mixed $token
-
[1] => 2|1|0
-
2: REMOVED: $token was removed from $from
-
1: ADDED: $token was added to $from
-
0: OLD: $token is not changed in $to
Parameters
- $from : array<string|int, mixed>|string
- $to : array<string|int, mixed>|string
- $lcs : LongestCommonSubsequence = null
Return values
array<string|int, mixed> —calculateEstimatedFootprint()
Calculates the estimated memory footprint for the DP-based method.
private
calculateEstimatedFootprint(array<string|int, mixed> $from, array<string|int, mixed> $to) : int|float
Parameters
- $from : array<string|int, mixed>
- $to : array<string|int, mixed>
Return values
int|float —checkIfDiffInOld()
Takes input of the diff array and returns the old array.
private
checkIfDiffInOld(array<string|int, mixed> $diff) : array<string|int, mixed>
Iterates through diff line by line,
Parameters
- $diff : array<string|int, mixed>
Return values
array<string|int, mixed> —detectUnmatchedLineEndings()
Returns true if line ends don't match on fromMatches and toMatches.
private
detectUnmatchedLineEndings(array<string|int, mixed> $fromMatches, array<string|int, mixed> $toMatches) : bool
Parameters
- $fromMatches : array<string|int, mixed>
- $toMatches : array<string|int, mixed>
Return values
bool —getArrayDiffParted()
private
static getArrayDiffParted(array<string|int, mixed> &$from, array<string|int, mixed> &$to) : array<string|int, mixed>
Parameters
- $from : array<string|int, mixed>
- $to : array<string|int, mixed>
Return values
array<string|int, mixed> —getBuffer()
Generates buffer in string format, returning the patch.
private
getBuffer(array<string|int, mixed> $diff, array<string|int, mixed> $old, int $start, int $end) : string
Parameters
- $diff : array<string|int, mixed>
- $old : array<string|int, mixed>
- $start : int
- $end : int
Return values
string —getDiffBufferElement()
Gets individual buffer element.
private
getDiffBufferElement(array<string|int, mixed> $diff, string $buffer, int $diffIndex) : string
Parameters
- $diff : array<string|int, mixed>
- $buffer : string
- $diffIndex : int
Return values
string —getDiffBufferElementNew()
Gets individual buffer element with opening.
private
getDiffBufferElementNew(array<string|int, mixed> $diff, string $buffer, int $diffIndex) : string
Parameters
- $diff : array<string|int, mixed>
- $buffer : string
- $diffIndex : int
Return values
string —getNewLineMatches()
Get new strings denoting new lines from a given string.
private
getNewLineMatches(string $string) : array<string|int, mixed>
Parameters
- $string : string
Return values
array<string|int, mixed> —selectLcsImplementation()
private
selectLcsImplementation(array<string|int, mixed> $from, array<string|int, mixed> $to) : LongestCommonSubsequence
Parameters
- $from : array<string|int, mixed>
- $to : array<string|int, mixed>
Return values
LongestCommonSubsequence —splitStringByLines()
Checks if input is string, if so it will split it line-by-line.
private
splitStringByLines(string $input) : array<string|int, mixed>
Parameters
- $input : string
Return values
array<string|int, mixed> —validateDiffInput()
Casts variable to string if it is not a string or array.
private
validateDiffInput(mixed $input) : string
Parameters
- $input : mixed