@@ -65,7 +65,23 @@ public function renderOutput(array $changes, object $subRenderer)
65
65
strlen ($ this ->options ['equalityMarkers ' ][1 ])
66
66
);
67
67
68
+ $ deprecationTriggered = false ;
68
69
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
+ }
69
85
$ output .= $ subRenderer ->generateBlockHeader ($ change );
70
86
switch ($ change ['tag ' ]) {
71
87
case 'equal ' :
@@ -80,6 +96,10 @@ public function renderOutput(array $changes, object $subRenderer)
80
96
case 'replace ' :
81
97
$ output .= $ subRenderer ->generateLinesReplace ($ change );
82
98
break ;
99
+ case 'ignore ' :
100
+ // TODO: Keep backward compatible with renderers?
101
+ $ output .= $ subRenderer ->generateLinesIgnore ($ change );
102
+ break ;
83
103
}
84
104
85
105
$ output .= $ subRenderer ->generateBlockFooter ($ change );
@@ -124,12 +144,14 @@ protected function renderSequences(): array
124
144
* 4 - The end line in the second sequence.
125
145
*
126
146
* 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
128
148
* the string in $newText from $startNew to $endNew.
129
149
* delete - The string in $oldText from $startOld to $endNew should be deleted.
130
150
* insert - The string in $newText from $startNew to $endNew should be inserted at $startOld in
131
151
* $oldText.
132
152
* 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.
133
155
*/
134
156
135
157
$ blockSizeOld = $ endOld - $ startOld ;
@@ -146,23 +168,23 @@ protected function renderSequences(): array
146
168
$ oldBlock = $ this ->formatLines (array_slice ($ oldText , $ startOld , $ blockSizeOld ));
147
169
$ newBlock = $ this ->formatLines (array_slice ($ newText , $ startNew , $ blockSizeNew ));
148
170
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.
151
173
$ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ oldBlock ;
152
174
$ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ newBlock ;
153
175
continue ;
154
176
}
155
177
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 .
158
180
$ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ oldBlock ;
181
+ continue ;
159
182
}
160
183
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 ;
165
186
}
187
+
166
188
$ changes [] = $ blocks ;
167
189
}
168
190
@@ -291,7 +313,7 @@ public function sequenceToArray(string $pattern, string $sequence): array
291
313
* E.g.
292
314
* <pre>
293
315
* 1234567
294
- * OLd => "abcdefg" Start marker inserted at position 3
316
+ * Old => "abcdefg" Start marker inserted at position 3
295
317
* New => "ab123fg" End marker inserted at position 6
296
318
* </pre>
297
319
*
0 commit comments