MediaWiki  master
Diff.php
Go to the documentation of this file.
1 <?php
32 class Diff {
33 
37  public $edits;
38 
43  protected $bailoutComplexity = 0;
44 
56  public function __construct( $from_lines, $to_lines ) {
57  $eng = new DiffEngine;
58  $eng->setBailoutComplexity( $this->bailoutComplexity );
59  $this->edits = $eng->diff( $from_lines, $to_lines );
60  }
61 
65  public function getEdits() {
66  return $this->edits;
67  }
68 
80  public function reverse() {
81  $rev = $this;
82  $rev->edits = [];
84  foreach ( $this->edits as $edit ) {
85  $rev->edits[] = $edit->reverse();
86  }
87 
88  return $rev;
89  }
90 
96  public function isEmpty() {
97  foreach ( $this->edits as $edit ) {
98  if ( $edit->type != 'copy' ) {
99  return false;
100  }
101  }
102 
103  return true;
104  }
105 
113  public function lcs() {
114  $lcs = 0;
115  foreach ( $this->edits as $edit ) {
116  if ( $edit->type == 'copy' ) {
117  $lcs += count( $edit->orig );
118  }
119  }
120 
121  return $lcs;
122  }
123 
132  public function orig() {
133  $lines = [];
134 
135  foreach ( $this->edits as $edit ) {
136  if ( $edit->orig ) {
137  array_splice( $lines, count( $lines ), 0, $edit->orig );
138  }
139  }
140 
141  return $lines;
142  }
143 
152  public function closing() {
153  $lines = [];
154 
155  foreach ( $this->edits as $edit ) {
156  if ( $edit->closing ) {
157  array_splice( $lines, count( $lines ), 0, $edit->closing );
158  }
159  }
160 
161  return $lines;
162  }
163 }
Diff\$edits
DiffOp[] $edits
Definition: Diff.php:37
DiffOp
The base class for all other DiffOp classes.
Definition: DiffOp.php:37
Diff\closing
closing()
Get the closing set of lines.
Definition: Diff.php:152
Diff\lcs
lcs()
Compute the length of the Longest Common Subsequence (LCS).
Definition: Diff.php:113
Diff\reverse
reverse()
Compute reversed Diff.
Definition: Diff.php:80
Diff\__construct
__construct( $from_lines, $to_lines)
Computes diff between sequences of strings.
Definition: Diff.php:56
DiffEngine\setBailoutComplexity
setBailoutComplexity( $value)
Sets the complexity (in comparison operations) that can't be exceeded.
Definition: DiffEngine.php:143
Diff\orig
orig()
Get the original set of lines.
Definition: Diff.php:132
Diff\isEmpty
isEmpty()
Check for empty diff.
Definition: Diff.php:96
Diff\getEdits
getEdits()
Definition: Diff.php:65
Diff\$bailoutComplexity
int $bailoutComplexity
If this diff complexity is exceeded, a ComplexityException is thrown 0 means no limit.
Definition: Diff.php:43
$lines
if(!file_exists( $CREDITS)) $lines
Definition: updateCredits.php:49
DiffEngine
This diff implementation is mainly lifted from the LCS algorithm of the Eclipse project which in turn...
Definition: DiffEngine.php:47
Diff
Class representing a 'diff' between two sequences of strings.
Definition: Diff.php:32