@@ -65,7 +65,23 @@ public function renderOutput(array $changes, object $subRenderer)
6565 strlen ($ this ->options ['equalityMarkers ' ][1 ])
6666 );
6767
68+ $ deprecationTriggered = false ;
6869 foreach ($ blocks as $ change ) {
70+ if (
71+ $ subRenderer instanceof MainRenderer &&
72+ !method_exists ($ subRenderer , 'generateLinesIgnore ' ) &&
73+ $ change ['tag ' ] == 'ignore '
74+ ) {
75+ if (!$ deprecationTriggered ) {
76+ trigger_error (
77+ 'The use of a subRenderer without method generateLinesIgnore() is deprecated! ' ,
78+ E_USER_DEPRECATED
79+ );
80+ $ deprecationTriggered = true ;
81+ }
82+ $ change ['tag ' ] =
83+ (count ($ change ['base ' ]['lines ' ]) > count ($ change ['changed ' ]['lines ' ])) ? 'delete ' : 'insert ' ;
84+ }
6985 $ output .= $ subRenderer ->generateBlockHeader ($ change );
7086 switch ($ change ['tag ' ]) {
7187 case 'equal ' :
@@ -80,6 +96,10 @@ public function renderOutput(array $changes, object $subRenderer)
8096 case 'replace ' :
8197 $ output .= $ subRenderer ->generateLinesReplace ($ change );
8298 break ;
99+ case 'ignore ' :
100+ // TODO: Keep backward compatible with renderers?
101+ $ output .= $ subRenderer ->generateLinesIgnore ($ change );
102+ break ;
83103 }
84104
85105 $ output .= $ subRenderer ->generateBlockFooter ($ change );
@@ -124,12 +144,14 @@ protected function renderSequences(): array
124144 * 4 - The end line in the second sequence.
125145 *
126146 * The different types of tags include:
127- * replace - The string from $startOld to $endOld in $oldText should be replaced by
147+ * replace - The string in $oldText from $startOld to $endOld, should be replaced by
128148 * the string in $newText from $startNew to $endNew.
129149 * delete - The string in $oldText from $startOld to $endNew should be deleted.
130150 * insert - The string in $newText from $startNew to $endNew should be inserted at $startOld in
131151 * $oldText.
132152 * equal - The two strings with the specified ranges are equal.
153+ * ignore - The string in $oldText from $startOld to $endOld and
154+ * the string in $newText from $startNew to $endNew are different, but considered to be equal.
133155 */
134156
135157 $ blockSizeOld = $ endOld - $ startOld ;
@@ -146,23 +168,23 @@ protected function renderSequences(): array
146168 $ oldBlock = $ this ->formatLines (array_slice ($ oldText , $ startOld , $ blockSizeOld ));
147169 $ newBlock = $ this ->formatLines (array_slice ($ newText , $ startNew , $ blockSizeNew ));
148170
149- if ($ tag = = 'equal ' ) {
150- // Old block equals New block
171+ if ($ tag != ' delete ' && $ tag ! = 'insert ' ) {
172+ // Old block " equals" New block or is replaced.
151173 $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ oldBlock ;
152174 $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ newBlock ;
153175 continue ;
154176 }
155177
156- if ($ tag == 'replace ' || $ tag == ' delete ' ) {
157- // Inline differences or old block doesn't exist in the new text .
178+ if ($ tag == 'delete ' ) {
179+ // Block of version1 doesn't exist in version2 .
158180 $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ oldBlock ;
181+ continue ;
159182 }
160183
161- if ($ tag == 'replace ' || $ tag == 'insert ' ) {
162- // Inline differences or the new block doesn't exist in the old text.
163- $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ newBlock ;
164- }
184+ // Block of version2 doesn't exist in version1.
185+ $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ newBlock ;
165186 }
187+
166188 $ changes [] = $ blocks ;
167189 }
168190
@@ -291,7 +313,7 @@ public function sequenceToArray(string $pattern, string $sequence): array
291313 * E.g.
292314 * <pre>
293315 * 1234567
294- * OLd => "abcdefg" Start marker inserted at position 3
316+ * Old => "abcdefg" Start marker inserted at position 3
295317 * New => "ab123fg" End marker inserted at position 6
296318 * </pre>
297319 *
0 commit comments